[英]Flexbox equal height not working
我一直在嘗試使用Flexbox創建一個3列布局,其中塊的高度相同。 在下面的第一張圖中,顯示了預期的行為(具有諷刺意味的是,它僅適用於IE11)。 在Microsoft Edge,Chrome和Firefox中,輸出如第二張圖所示,這不是我想要完成的。
在瀏覽Stackoverflow和Google之后,我似乎無法找到解決問題的方法。 如果有人能夠在出現問題的地方幫助我,那將非常感激!
JSFiddle: http : //jsfiddle.net/uyvhrjjb/1/
CSS:
#threeblocks {
width: 100%;
overflow: hidden;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-align-items: stretch;
-ms-flex-align: stretch;
align-items: stretch;
}
#threeblocks .block {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
align-self: stretch;
width: 30%;
margin: auto;
border: 1px solid #B8B8B8;
}
HTML:
<div id="threeblocks">
<div class="block" style="text-align: center">
<p><strong>Title 1</strong></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam egestas, lorem nec vestibulum fermentum, massa magna efficitur augue, sed fermentum ligula eros sit amet eros.</p>
</div>
<div class="block" style="text-align: center">
<p><strong>Title 2</strong></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam egestas, lorem nec vestibulum fermentum, massa magna efficitur augue, sed fermentum ligula eros sit amet eros. Mauris est velit, scelerisque eu libero ac, bibendum consequat neque. Integer sed ligula sed erat rhoncus bibendum. Donec eget tortor dui. Vestibulum ex dui, consectetur a iaculis vestibulum, eleifend ut nibh. Nullam a ultrices dui. Sed sit amet augue euismod, vehicula leo id, convallis orci.</p>
</div>
<div class="block" style="text-align: center">
<p><strong>Title 3</strong></p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam egestas, lorem nec vestibulum fermentum, massa magna efficitur augue, sed fermentum ligula eros sit amet eros.</p>
</div>
</div>
您可以刪除項目的邊距,它的工作原理
http://jsfiddle.net/uyvhrjjb/4/
#threeblocks {
width: 100%;
overflow: hidden;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-align-items: stretch;
-ms-flex-align: stretch;
align-items: stretch;
}
#threeblocks .block {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
align-self: stretch;
width: 30%;
border: 1px solid #B8B8B8;
}
從規則中刪除保證金:auto:#threeblocks .block
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.