Flex布局时,并且设置warp,父层宽度如何自适应?

图片描述

.flex{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  border: 1px solid green;
}

.item{
  margin-bottom: 5px;
  margin-right: 5px;
  background: pink;
  width: 70px;
  height: 50px;
  line-height: 50px;
  text-align: center;
}

 <div class="flex">
   <div class="item">
   </div>
   <div class="item">
   </div>
   ...
 </div>

换行后,父层DIV 如何宽度不留白

阅读 6.4k
3 个回答
新手上路,请多包涵

父元素添加 width: max-content

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题