【问题标题】:How to make profile cards stack on mobile?如何在手机上制作个人资料卡?
【发布时间】:2022-01-18 23:32:05
【问题描述】:

我已经创建了个人资料卡,我需要它们在移动设备上以 2 对叠放。 卡片在桌面上并排显示,这很好,但移动视图需要调整。 我需要与所有屏幕尺寸兼容的配件。

提前感谢您的任何帮助,非常感谢。 :)

    .card {
  box-shadow: 0 4px 8px 0 rgb(255, 255, 255);
  max-width: 350px;
  margin: auto;
  text-align: center;
  padding: 60px;
}

.title {
  color: rgb(255, 255, 255);
  font-size: 18px;
}

button {
  border: none;
  outline: 0;
  display: inline-block;
  padding: 8px;
  color: white;
  background-color: #000000;
  text-align: center;
  cursor: pointer;
  width: 100%;
  font-size: 18px;
}

a {
  text-decoration: none;
  font-size: 30px;
  color: rgb(255, 255, 255);
}

button:hover, a:hover {
  opacity: 0.7;
}

h1 {
  color:#ffffff;
  font-size: 32px;
}

.flex-container {
  display: flex;
}

.flex-child {
  flex: 1;
  border: 2px solid yellow;
}

.flex-child:first-child {
  margin-right: 20px;
}
     <div class="flex-container">
         <div class="flex-child-Tee">
      <div class="card">
         <img src="img/Tee.png" alt="Tee" style="width:100%">
         <h1>Tristen</h1>
         <p class="title">Founder</p>
         <a href="#"><i class="fa fa-twitter"></i></a>
         <p><button>Contact</button></p>
       </div>
      </div>
      <div class="flex-child-Byrd">
       <div class="card">
         <img src="img/Byrd.png" alt="Byrdman" style="width:100%">
         <h1>Landon</h1>
         <p class="title">Founder</p>
         <a href="#"><i class="fa fa-twitter"></i></a>
         <p><button>Contact</button></p>
       </div>
      </div>
      </div>

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    代替

    .flex-container {
              display: flex;
            }
    

    @media only screen and (min-width: 600px) {
         .flex-container {
          display: flex;
        }
    }
    
    @media only screen and (max-width: 600px) {
         .flex-container {
          display: block;
        }
    }
    

    【讨论】:

      【解决方案2】:

      默认情况下,flexbox 有一个flex-direction: row;。您可以设置一个media query 指示浏览器更改为flex-direction: column; 用于移动屏幕。

      .card {
        box-shadow: 0 4px 8px 0 rgb(255, 255, 255);
        max-width: 350px;
        margin: auto;
        text-align: center;
        padding: 60px;
      }
      
      .title {
        color: rgb(255, 255, 255);
        font-size: 18px;
      }
      
      button {
        border: none;
        outline: 0;
        display: inline-block;
        padding: 8px;
        color: white;
        background-color: #000000;
        text-align: center;
        cursor: pointer;
        width: 100%;
        font-size: 18px;
      }
      
      a {
        text-decoration: none;
        font-size: 30px;
        color: rgb(255, 255, 255);
      }
      
      button:hover, a:hover {
        opacity: 0.7;
      }
      
      h1 {
        color:#ffffff;
        font-size: 32px;
      }
      
      .flex-container {
        display: flex;
      }
      
      .flex-child {
        flex: 1;
        border: 2px solid yellow;
      }
      
      .flex-child:first-child {
        margin-right: 20px;
      }
      
      @media only screen and (max-width: 800px) {
        .flex-container {
          flex-direction: column;
        }
      }
      <div class="flex-container">
         <div class="flex-child-Tee">
            <div class="card">
               <img src="img/Tee.png" alt="Tee" style="width:100%">
               <h1>Tristen</h1>
               <p class="title">Founder</p>
               <a href="#"><i class="fa fa-twitter"></i></a>
               <p><button>Contact</button></p>
            </div>
         </div>
         <div class="flex-child-Byrd">
            <div class="card">
               <img src="img/Byrd.png" alt="Byrdman" style="width:100%">
               <h1>Landon</h1>
               <p class="title">Founder</p>
               <a href="#"><i class="fa fa-twitter"></i></a>
               <p><button>Contact</button></p>
            </div>
         </div>
      </div>

      【讨论】:

        猜你喜欢
        • 2020-12-14
        • 2020-08-26
        • 1970-01-01
        • 1970-01-01
        • 2021-07-19
        • 2017-09-06
        • 1970-01-01
        • 2016-04-02
        • 2012-06-08
        相关资源
        最近更新 更多