伪类选择器
链接伪类选择器
- :link
- :visited
- :hover
- :active
注意:书写的时候尽量不要颠倒顺序,记忆顺序是 love hate
一般工作中经常使用的属性如下:
<style>
a{
font-size: 14px;
font-weight: bold;
color: darkgray;
}
a:hover{
color: red;
}
</style>
</head>
<body>
<a href="">首页</a>
</body>
结构伪类选择器(css3)
- :first-child:选取父元素的首个子元素的指定选择器
- :last-child:选取父元素的最后一个子元素的制定选择器
- :nth-child(n):匹配属于父元素的第N个子元素,不论元素的类型
- :nth-last-child(n):匹配从父元素最后一个子元素开始倒数的子元素
代码示例:
<style>
li:first-child{ /*选择第一个子元素*/
color: red;
}
li:last-child{ /*选择最后一个子元素*/
color: blue;
}
li:nth-child(3){/*选择第三个子元素 n 代表第几个的意思*/
color: orange;
}
</style>
</head>
<body>
<ul>
<li>第一个子元素</li>
<li>第二个子元素</li>
<li>第三个子元素</li>
<li>第四个子元素</li>
<li>第五个子元素</li>
<li>第六个子元素</li>
<li>第七个子元素</li>
</ul>
</body>