[英]Equate height of all divs using just CSS
我已經使用了display:table屬性,但是表格單元格的高度仍然不相等。 有沒有辦法使它們相等而不使用JavaScript或jQuery? 必須牢記Internet Explorer的兼容性。
<div class="envelope">
<div class="fill col">
ABC
<br><br><br>
</div>
<div class="fill ">DEF</div>
<div class="fill col">
XYZ
<br><br><br>
<br><br><br>
</div>
</div>
這是CSS
.envelope{
border:1px solid #000;
border-radius:5px;
display:table;
width:300px;
}
.fill{
background:#dddddd;
border-right:1px solid #000;
float:left;
width:30%;
padding:1%;
display:table-cell;
}
.col{
background:#ff44ff;
}
每個人都回答了,但是沒有人說為什么會這樣:
float
屬性時, float
元素將從正常流中取出,並沿其容器的左側或右側放置。 float
可以修改顯示值的計算值:
display: table-cell
變為display: block
。 height
值(可能因為它是作為display: block
來計算的),則具有相同高度的解決方案將其刪除float:left
像這樣更新css
.fill{
background:#dddddd;
border-right:1px solid #000;
width:30%;
padding:1%;
display:table-cell;
}
我刪除了float:left
刪除float:left將解決您的問題:
https://jsfiddle.net/yt18kLos/1/
.envelope{
border:1px solid #000;
border-radius:5px;
display:table;
width:300px;
}
.fill{
background:#dddddd;
border-right:1px solid #000;
/*float:left;*/
width:30%;
padding:1%;
display:table-cell;
}
.col{
background:#ff44ff;
}
移除float:left;
會解決你的問題
CSS
.fill{
background:#dddddd;
border-right:1px solid #000;
width:30%;
padding:1%;
display:table-cell;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.