我有一个关于嵌套 DIV 样式的问题(请看这里的示例)。
我有一些嵌套的 DIV(带有 class="box"
),它们是动态渲染的,例如:
<div class="box" id="1">
other content
<div class="box" id="2">
<div class="box" id="3">
</div>
</div>
other content
<div class="box" id="4">
</div>
</div>
other content
我希望这些 DIV 底部有边框:
<style>
div.box {border-bottom: solid 1px gray;}
</style>
问题在于,当两个嵌套的DIV底部边框相邻时(例如box 2和3或box 1和4),结果是一个高度为2(或更多像素)的灰色线条。
如果它们相邻,是否可能折叠嵌套DIV的边框?
我尝试添加border-collapse:collapse,但没有帮助。
:last-child
不考虑类名,只有在父元素的最后一个子元素匹配div.box
时才能生效。 - Hashem Qolamidiv.box
,那么使用:last-child
也可能没有问题。但这只是需要记在心里的一点小细节。 - BoltClockother content
可能会出现在第四个.box
元素之后(http://jsfiddle.net/hashem/wP3CB/3/),在这种情况下,该框应有一个边框。 - Hashem Qolami