且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用CSS类在第一个,第二个或第三个html元素中选择子元素?

更新时间:2021-12-02 22:19:04

您的< a> 元素不是相邻的兄弟姐妹(或根本不是兄弟姐妹),因此相邻的兄弟姐妹选择器(+ )不适用于他们.

Your <a> elements are not adjacent siblings (or siblings at all), so the adjacent sibling selector (+) doesn't apply to them.

div元素是同级.

body div:first-child a:hover//The first child
{
    font-size:30px;
    color:yellow;
}
body  div+div a:hover  //the second child
{
    font-size:40px;
    color:red;
}
body div+div+div a:hover  //the third child
{
    font-size:50px;
    color:#fff;
}

您无需使用,也不需要使用此类.

You aren't using, and don't need to use, classes for this.