Bla*_*olf 6 html css css-selectors
有没有办法选择一个CSS元素作为其父元素的第一个子元素,计算文本节点?如果标题位于其父级的顶部,我想删除标题的上边距,但如果我使用:
#content h1 {
margin-top: 1em;
}
#content h1:first-child {
margin-top: 0;
}
Run Code Online (Sandbox Code Playgroud)
并有一些HTML喜欢
<div id="content">
This is some text.
<h1>A heading</h1>
Some more text.
</div>
Run Code Online (Sandbox Code Playgroud)
保证金仍然被删除.CSS有什么方法可以防止这种情况发生吗?
删除margin,而不仅仅是margin-top, h1 元素将下一个元素向下推
#content h1 {
margin-top: 1em;
}
#content h1:first-child {
margin: 0px;
}
Run Code Online (Sandbox Code Playgroud)
如果您想删除除第一个之外的所有内容
#content h1:not(:first-child) {
margin: 0px;
}
Run Code Online (Sandbox Code Playgroud)