html - 最后一个 child 不能正常使用文章

标签 html css

<分区>

为什么 article 的行为与 last-child 相关的 div 不同

HTML

<div class="parent">
<div class="example">111</div>
<div class="example">111</div>
<div class="example">111</div>
<div class="example">111</div>
</div>

<br>

<div class="parent2">
<article class="example">111</div>
<article class="example">111</div>
<article class="example">111</div>
<article class="example">111</div>
</div>

CSS

.parent .example{ background-color: red;}
.parent .example:last-child{background-color: yellow;}

.parent2 .example{ background-color: red;}
.parent2 .example:last-child{background-color: yellow;}

演示:http://jsfiddle.net/chLLa/1/

最佳答案

您没有正确关闭标签

<div class="parent">
<div class="example">111</div>
<div class="example">111</div>
<div class="example">111</div>
<div class="example">111</div>
</div>

<br>

<div class="parent2">
<article class="example">111</article>
<article class="example">111</article>
<article class="example">111</article>
<article class="example">111</article>
</div>

关于html - 最后一个 child 不能正常使用文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14407679/

上一篇:css - 标题元素在 IE8 中被隐藏

下一篇:javascript - 如何让页面内容始终出现在导航栏下方?

相关文章:

javascript - 使用 javascript 和 css 消失 php 抓取/输出数据的文本

html - 为什么链接与文本重叠?

html - div 旁边的形状

html - 没有宽度/高度的 SVG 以自然大小呈现

html - z-index 和 position fixed 如何在 css 中协同工作

html - bool 玛导航栏菜单在移动设备上默认打开

javascript - 仅显示 SVG 的一半

html - 在多维数据集投资组合中创建组

html - 在 XHTML/HTML 中,哪些元素具有语义值,哪些是表示性的,哪些不属于这两个类别?

javascript - 单击事件触发后跨度不显示