我有一个笨重的 css 块,我用它来设置元素第一个子元素的 margin-top 。第一个子元素可以是任何标签。
.comment-description p:first-child,
.comment-description ol:first-child,
.comment-description ul:first-child,
.comment-description pre:first-child,
.comment-description blockquote:first-child
{
margin-top:0px;
}
Run Code Online (Sandbox Code Playgroud)
我确信我可以把它砍掉,但由于我不经常设计,所以我不记得更好的方法。我可以使用类似的东西吗:
.comment-description *:first-child
{
margin-top:0px;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是这不起作用。
您可能感兴趣:
.comment-description > :first-child {}
- 仅选择直系子代
或者
.comment-description :first-child
- 选择所有子元素的第一个子元素
看:
归档时间: |
|
查看次数: |
3857 次 |
最近记录: |