【发布时间】:2014-01-15 06:07:42
【问题描述】:
这个问题来自this existing question,我提供了解决方案,但无法解释原因。
我已经将他们的小提琴完全剥离并拥有以下 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;
}
只有 .cell-1 有宽度,即 1%。 This is the result (fiddle link):
如果我随后将.cell-1 的宽度增加到比其内容更宽的值,例如 10%(我认为这就是模式),那么第二个单元格将变得更窄。为什么?这个宽度是从哪里来的?
This is the result (fiddle link).
如果我再举第二个例子,但将width: 100% 添加到.table,那么它会再次回到 100%。 Here's the result of that (fiddle link)。
我确信有一个合乎逻辑的解释,但我只是没有看到它。有人吗?
【问题讨论】:
标签: html css css-tables