簡體   English   中英

小屏幕上的響應式 Flexbox

[英]Responsive Flexbox on small screens

我在大屏幕上有 4 個按行順序排列的圖標,但在小屏幕上(比方說小於 768px),我需要按行順序排列 2 個圖標。

這是我當前的代碼:

 .welcome { display: flex; justify-content: space-around; } @media (max-width: 768px) { /* I need the code here */ }
 <section class="container text-center"> <h2 id="h2-welcome"><strong>Welcome to our website</strong></h2> <div class="welcome"> <div class="welcome-content"> <i class="fas fa-life-ring fa-5x"></i> <p>Sherbimi 24/7</p> </div> <div class="welcome-content"> <i class="fas fa-tachometer-alt fa-5x"></i> <p>Shpejt & Stabil</p> </div> <div class="welcome-content"> <i class="fas fa-globe-europe fa-5x"></i> <p>Kanale nga gjithe Bota</p> </div> <div class="welcome-content"> <i class="fas fa-user-shield fa-5x"></i> <p>Sigurt & Shpejt</p> </div> </div> </section>

您可以使用flex-wrap: wrap; 強制新的訂單項並使用flex: 0 0 50%; 用於占用一行的兩個項目的空間。

.welcome{
     flex-wrap: wrap;
}

@media (max-width: 768px) {
     flex: 0 50%;
}

這是一個 CodePen: https ://codepen.io/alessandroinfo/pen/rEBKMd

使用flex: 0 1 50%; media和設置flex: 0 1 50%; .welcome

 .welcome { display: flex; justify-content: space-around; flex-wrap: wrap; } @media (max-width: 768px) { .welcome div { flex: 0 1 50%; } }
 <section class="container text-center"> <h2 id="h2-welcome">Welcome to our website</h2> <div class="welcome"> <div class="welcome-content"> <i class="fas fa-life-ring fa-5x"></i> <p>Sherbimi 24/7</p> </div> <div class="welcome-content"> <i class="fas fa-tachometer-alt fa-5x"></i> <p>Shpejt & Stabil</p> </div> <div class="welcome-content"> <i class="fas fa-globe-europe fa-5x"></i> <p>Kanale nga gjithe Bota</p> </div> <div class="welcome-content"> <i class="fas fa-user-shield fa-5x"></i> <p>Sigurt & Shpejt</p> </div> </div> </section>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM