简体   繁体   English

小屏幕上的响应式 Flexbox

[英]Responsive Flexbox on small screens

I have 4 icons in row order on large screens, but on small screen (let's say less than 768px), I need 2 icons in row order.我在大屏幕上有 4 个按行顺序排列的图标,但在小屏幕上(比方说小于 768px),我需要按行顺序排列 2 个图标。

Here is my current code :这是我当前的代码:

 .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>

You can use flex-wrap: wrap;您可以使用flex-wrap: wrap; for force the new line items and using flex: 0 0 50%;强制新的订单项并使用flex: 0 0 50%; for take the space of two item of a row.用于占用一行的两个项目的空间。

.welcome{
     flex-wrap: wrap;
}

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

This is a CodePen: https://codepen.io/alessandroinfo/pen/rEBKMd这是一个 CodePen: https ://codepen.io/alessandroinfo/pen/rEBKMd

Use flex: 0 1 50%;使用flex: 0 1 50%; in media and set flex: 0 1 50%;media和设置flex: 0 1 50%; to .welcome.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