假设我有这样的标记:
<div class="container"> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> <div class="column"> <div class="cell"></div> <div class="cell"></div> <div class="cell"></div> </div> ... </div>
然后是CSS
.container { display: table; border-collapse: collapse; } .column { float: left; overflow: hidden; width: 120px; } .cell { display: table-cell; border: 1px solid red; width: 120px; height: 20px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
我的外部div和display: table; border-collapse: collapse;和单元格display: table- cell为何仍不折叠?我在这里想念什么?
display: table; border-collapse: collapse;
display: table- cell
顺便说一下,一列中单元格的数量可能是可变的,所以我不能只在一侧有边框。
这是一个演示
首先,您需要更正其语法错误
display: table-cell;
不 diaplay: table-cell;
diaplay: table-cell;
.container { display: table; border-collapse:collapse } .column { display:table-row; } .cell { display: table-cell; border: 1px solid red; width: 120px; height: 20px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }