简体   繁体   English

为什么 CSS Flex-box 没有包裹一半的物品?

[英]Why is CSS Flex-box not wrapping half of the items?

Question问题

For some reason, half of the items in the flex-box are not wrapping.由于某种原因,flex-box 中有一半的项目没有包装。 After inspecting the elements in the browser (picture below) it seems as thought they are taking up a whole container width's worth of space.检查浏览器中的元素(下图)后,似乎认为它们占用了整个容器宽度的空间。 Wheras they are only supposed to take up a third of the space each.然而它们每个只应该占用三分之一的空间。

在此处输入图像描述

Please find a minimum representative sample of the code:请找到代码的最低代表性示例:

 #portfolio #portfolio-flters { padding: 0; margin: 5px 0 35px 0; list-style: none; } #portfolio #portfolio-flters li { margin: 15px 15px 15px 0; display: inline-block; padding: 6px 20px; line-height: 20px; margin-bottom: 5px; } #portfolio #portfolio-flters li:last-child { margin-right: 0; } #portfolio.portfolio-item { position: relative; overflow: hidden; margin-bottom: 30px; } #portfolio.portfolio-item.portfolio-wrap { overflow: hidden; position: relative; border-radius: 6px; margin: 0; } #portfolio.portfolio-item.portfolio-wrap.portfolio-info { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; -webkit-box-orient: vertical; -webkit-box-direction: normal; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; text-align: center; } #portfolio.portfolio-item.portfolio-wrap.portfolio-info h4 { line-height: 1px; margin-bottom: 14px; padding-bottom: 0; } #portfolio.portfolio-item.portfolio-wrap.portfolio-info p { padding: 0; margin: 0; } #portfolio.portfolio-item.portfolio-wrap.portfolio-info.link-preview, #portfolio.portfolio-item.portfolio-wrap.portfolio-info.link-details { display: inline-block; line-height: 1; text-align: center; width: 36px; height: 36px; border-radius: 50%; margin: 10px 4px 0 4px; } #portfolio.portfolio-item.portfolio-wrap.portfolio-info.link-preview i, #portfolio.portfolio-item.portfolio-wrap.portfolio-info.link-details i { padding-top: 6px; }
 <section id="portfolio" class="clearfix"> <div class="container"> <header class="section-header"> <h3 class="section-title">Our Portfolio</h3> </header> <div class="row"> <div class="col-lg-12"> <ul id="portfolio-flters"> <li data-filter="*" class="filter-active">All</li> <li data-filter=".filter-app">App</li> <li data-filter=".filter-card">Card</li> <li data-filter=".filter-web">Web</li> </ul> </div> </div> <div class="row portfolio-container"> <div class="col-lg-4 col-md-6 portfolio-item filter-app"> <div class="portfolio-wrap"> <img src="placehold.co" class="img-fluid" alt=""> <div class="portfolio-info"> <h4>T</h4> <p>T</p> </div> </div> </div> <div class="col-lg-4 col-md-6 portfolio-item filter-web" data-wow-delay="0.1s"> <div class="portfolio-wrap"> <img src="placehold.co" class="img-fluid"> <div class="portfolio-info"> <h4></h4> <p></p> <div> <a class="link-details" title="More Details"><i class="ion ion-android-open"></i></a> </div> </div> </div> </div> <,--These elements repeat, essentially the only thing that differs is the size of the image and the image file, the links etc-->

在此处输入图像描述

From the looks of it you need to add the .col divs inside a .row .portfolio-container div.从外观上看,您需要在.row .portfolio-container div 中添加.col div。 But all your problematic divs seem to be outside the .row .portfolio-container so maybe that explains why half of your divs are taking all the space.但是所有有问题的 div 似乎都在.row .portfolio-container之外,所以也许这可以解释为什么一半的 div 占用了所有空间。 Can you double check that?你能仔细检查一下吗?

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

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