要使用 CSS 对页面中的链接设置不同颜色和样式,可以使用伪类选择器 :link、:visited、:hover、:active。其中,:link 用于设置链接的默认样式,:visited 用于设置已访问链接的样式,:hover 用于设置鼠标悬停在链接上时的样式,:active 用于设置链接被点击时的样式。
要设置链接的颜色,可以使用 color 属性。要设置链接的下划线,可以使用 text-decoration 属性。要设置链接的字体加粗,可以使用 font-weight 属性。
以下是一个示例代码,它将未访问的链接设置为红色、有下划线,已访问的链接设置为灰色、有下划线,鼠标悬停在链接上时设置为蓝色、有下划线,链接被点击时设置为绿色、有下划线:
a:link {
color: red;
text-decoration: underline;
}
a:visited {
color: gray;
text-decoration: underline;
}
a:hover {
color: blue;
text-decoration: underline;
}
a:active {
color: green;
text-decoration: underline;
}
其中,:link、:visited、:hover、:active 都是伪类选择器,用于选择不同状态的链接。color 属性用于设置字体颜色,text-decoration 属性用于设置文本装饰,如下划线。