This question comes out of this existing question which I provided a solution to, but couldn't provide an explanation as to why.
I've stripped their fiddle right down to the bare bones and have the following HTML / CSS:
<div class="table">
<span class="cell-1">cell 1</span>
<span class="cell-2">cell 2</span>
</div>
.table {
display: table;
}
.cell-1, .cell-2 {
display: table-cell;
padding: 6px 12px;
border: 1px solid #ccc;
}
.cell-1 {
padding: 6px 12px;
background-color: #eee;
border-right: 0;
border-radius: 4px 0 0 4px;
width: 1%; /* *** FOCUS HERE *** */
}
.cell-2 {
border-radius: 0 4px 4px 0;
}
Only .cell-1
has a width and that is 1%. This is the result (fiddle link):
If I then increase the width of .cell-1
to a value where it is wider than it's content, say 10% (I think that's the pattern anyway) then second cell will become narrower. Why? Where does that width come from?
This is the result (fiddle link).
If I then take the second example, but add width: 100%
to the .table
then it goes back to 100% again. Here's the result of that (fiddle link).
I'm sure there's a logical explanation but I'm just not seeing it. Anyone?