I've been put in a position where I need to use the display:table-cell command for div elements.
However I've discovered that the "cells" will only work correctly if a percentage is added to the width.
In this fiddle http://jsfiddle.net/NvTdw/ when I remove the percentage width the cells do not have equal widths, however when a percentage value is added to the width all is well, but only when that percentage is equal to the proportion of max no of divs, so for four columns 25%, five 20% and in this case five at 16.666%.
I thought maybe adding a percentage of less - say 1% would be a good fix all, but the cells fall out of line again.
Why is this?
.table {_x000D_
display: table;_x000D_
height: 200px;_x000D_
width: 100%;_x000D_
}_x000D_
_x000D_
.cell {_x000D_
display: table-cell;_x000D_
height: 100%;_x000D_
padding: 10px;_x000D_
width: 16.666%;_x000D_
}_x000D_
_x000D_
.grey {_x000D_
background-color: #666;_x000D_
height: 100%;_x000D_
text-align: center;_x000D_
font-size: 48px;_x000D_
color: #fff;_x000D_
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;_x000D_
font-weight: 300;_x000D_
}
_x000D_
<div class="table">_x000D_
<div class="cell">_x000D_
<div class="grey">Block one</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block two</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block three</div>_x000D_
</div>_x000D_
</div>_x000D_
<div class="table">_x000D_
<div class="cell">_x000D_
<div class="grey">Block</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block two</div>_x000D_
</div>_x000D_
</div>_x000D_
<div class="table">_x000D_
<div class="cell">_x000D_
<div class="grey">Block one</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block two</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block three</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block four</div>_x000D_
</div>_x000D_
</div>_x000D_
<div class="table">_x000D_
<div class="cell">_x000D_
<div class="grey">x</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">xx</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">xxx</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">xxxx</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">xxxxxx</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block five test</div>_x000D_
</div>_x000D_
</div>_x000D_
<div class="table">_x000D_
<div class="cell">_x000D_
<div class="grey">Block</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block two</div>_x000D_
</div>_x000D_
<div class="cell">_x000D_
<div class="grey">Block three</div>_x000D_
</div>_x000D_
</div>
_x000D_
This question is related to
html
css
css-tables
You just need to add 'table-layout: fixed;'
.table {
display: table;
height: 100px;
width: 100%;
table-layout: fixed;
}
Note also that vertical-align:top;
is often necessary for correct table cell appearance.
Source: Stackoverflow.com