假设我有以下标记:http://jsfiddle.net/R8eCr/1/
<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>
Run Code Online (Sandbox Code Playgroud)
然后是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;
}
Run Code Online (Sandbox Code Playgroud)
我有外部div display: table; border-collapse: collapse;和细胞,display: table-cell他们为什么还没有崩溃?我在这里错过了什么?
顺便说一下,列中可能有不同数量的单元格,因此我不仅可以在一侧有边框.
iam*_*der 82
使用简单的负边距而不是使用显示表.
在小提琴JS Fiddle中更新
.container {
border-style: solid;
border-color: red;
border-width: 1px 0 0 1px;
display: inline-block;
}
.column {
float: left; overflow: hidden;
}
.cell {
border: 1px solid red; width: 120px; height: 20px;
margin:-1px 0 0 -1px;
}
.clearfix {
clear:both;
}
Run Code Online (Sandbox Code Playgroud)
use*_*559 71
而是border使用box-shadow:
box-shadow:
2px 0 0 0 #888,
0 2px 0 0 #888,
2px 2px 0 0 #888, /* Just to fix the corner */
2px 0 0 0 #888 inset,
0 2px 0 0 #888 inset;
Run Code Online (Sandbox Code Playgroud)
演示:http://codepen.io/Hawkun/pen/rsIEp
Hus*_*hme 35
这是一个演示
首先你需要纠正你的语法错误
display: table-cell;
Run Code Online (Sandbox Code Playgroud)
不 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;
}
Run Code Online (Sandbox Code Playgroud)
小智 11
为什么不使用outline?这就是你想要的:
outline: 1px solid red;
Run Code Online (Sandbox Code Playgroud)
在这里,我展示了边框折叠的多种变体。(使用 Bootstrap 网格):https ://codepen.io/leonardo1024/pen/KgbNGr
您还可以使用负边距:
.column {
float: left;
overflow: hidden;
width: 120px;
}
.cell {
border: 1px solid red;
width: 120px;
height: 20px;
box-sizing: border-box;
}
.cell:not(:first-child) {
margin-top: -1px;
}
.column:not(:first-child) > .cell {
margin-left: -1px;
}Run Code Online (Sandbox Code Playgroud)
<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 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>Run Code Online (Sandbox Code Playgroud)
你需要使用display: table-row而不是float: left;你的专栏,显然正如@Hushme更正你diaplay: table-cell的display: table-cell;
.container {
display: table;
border-collapse: collapse;
}
.column {
display: table-row;
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
102627 次 |
| 最近记录: |