繁体   English   中英

当宽度小于最大宽度时如何包装元素?

[英]how to wrap element when width is less than max width?

我想在大于600px1 below another two column布局或two box in a row box

这是我的代码

https://codesandbox.io/s/affectionate-cartwright-pw2mq?file=/src/styles.css:182-396

<div class="abc">
      <div class="card"></div>
      <div class="card"></div>
    </div>


.abc {
  display: flex;
  max-width: 600px;
  justify-content: space-around;
  flex-wrap: wrap;
  border: 2px dotted pink;
}
.card {
  padding: 100px;
  background-color: aqua;
  border: 2px solid;
  margin: 5px;
}

我的问题是当宽度小于600时它没有包装盒子。

在此处输入图像描述

您可以使用 CSS 媒体查询来完成。 像这样的东西。

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

尝试这个:

DIV默认是block ,所以要保留卡片display:inline-block; .

.abc {
 display: flex;
 max-width: 600px;
 justify-content: space-around;
 flex-wrap: wrap;
 border: 2px dotted pink;
}
 .card {
  padding: 100px;
  background-color: aqua;
  border: 2px solid;
 margin: 5px;
 }

@media only screen and (max-width: 600px) {
 .abc {
  display: inline-block;
   }
  }

全屏环绕:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM