CSS 通配符:first-child

Kev*_*Kev 3 css css-selectors

我有一个笨重的 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)

不幸的是这不起作用。

Hal*_*zed 5

您可能感兴趣:

.comment-description > :first-child {}- 仅选择直系子代

或者

.comment-description :first-child- 选择所有子元素的第一个子元素

看:

http://jsfiddle.net/9VqsW/1/