【发布时间】:2018-04-23 18:59:55
【问题描述】:
我想要一个容器 flex div,每行有 3 个元素,问题是当我添加第四个元素(它应该自动换行到第二行)时,它会停留在单行上并缩小其他元素。我启用了 flex-wrap: wrap;
这是我的代码:
<div class="border" style="width:100%; height:auto; position:relative; display:flex; flex-wrap:wrap; justify-content:flex-start; ">
<div class="border" style="flex:1 1 33.33%; height:400px; margin-bottom:10px; margin-right:10px; text-align:center; padding:10px 10px;">
<img src="https://images.petsmartassets.com/is/image/PetSmart/ARTHMB-HowMuchExerciseDoesMyDogNeed-20160818?$AR1104$" style="width:100%; height:70%; position:relative;">
<a href="#">
<h6 style="color: rgba(0, 0, 255, 0.6); font-weight:900; font-size:12px; margin-top:10px; ">HEALTH & CARE</h6>
</a>
<h5 style="font-weight:600;">How much exercise does my dog need?</h5>
</div>
<div class="border" style="flex:1 1 33.33%; height:400px; margin-bottom:10px; margin-right:10px; text-align:center; padding:10px 10px;">
<img src="https://images.petsmartassets.com/is/image/PetSmart/ARTHMB-HomeToRoamFindTheRightDogForYourApartment-20160818?$AR1104$" style="width:100%; height:70%; position:relative;">
<a href="#">
<h6 style="color: rgba(0, 0, 255, 0.6); font-weight:900; font-size:12px; margin-top:10px; ">HEALTH & CARE</h6>
</a>
<h5 style="font-weight:600;">How much exercise does my dog need?</h5>
</div>
<div class="border" style="flex:1 1 33.33%; height:400px; margin-bottom:10px; text-align:center; padding:10px 10px;">
<img src="https://images.petsmartassets.com/is/image/PetSmart/ARTHMB-GoDogGoCrateCarrierGateOrKennel-20160818?$AR1104$" style="width:100%; height:70%; position:relative;">
<a href="#">
<h6 style=" color: rgba(0, 0, 255, 0.6); font-weight:900; font-size:12px; margin-top:10px; ">HEALTH & CARE</h6>
</a>
<h5 style="font-weight:600;">How much exercise does my dog need?</h5>
</div>
<div class="border" style="flex:1 1 33.33%; height:400px; margin-bottom:10px; text-align:center; padding:10px 10px;">
<img src="https://images.petsmartassets.com/is/image/PetSmart/ARTHMB-GoDogGoCrateCarrierGateOrKennel-20160818?$AR1104$" style="width:100%; height:70%; position:relative;">
<a href="#">
<h6 style=" color: rgba(0, 0, 255, 0.6); font-weight:900; font-size:12px; margin-top:10px; ">HEALTH & CARE</h6>
</a>
<h5 style="font-weight:600;">How much exercise does my dog need?</h5>
</div>
</div>
【问题讨论】:
-
谢谢我修复了它,但现在还有另一个问题,我的行是两个元素而不是每行三个元素,我该如何解决这个问题?