我在CSS中输入#id:first-child{
xxx;
xxx;
}
这样用法有错吗?为什么我不用伪类,直接给需要的对象加了class,然后直接class引用才成功..
ringa_lee2017-04-17 11:07:04
MDN related introduction
The first sub-element under id
mentioned by the questioner is probably not used in this way.
You are probably referring to the descendant selector. Can you determine the type of the child element? If so, just
#id element:first-child{
}
For example, id
is the first child element test
ul
of li
’s
#test li:first-child{
color:red;
}
Can you try this?
#test *:first-child{
color:red;
}
Effect:
http://jsfiddle.net/8f2ff6ks/
PHP中文网2017-04-17 11:07:04
The first-child selector is used to select the specified selector that belongs to the first child element of its parent element