且构网

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

如何在CSS中设置一种样式来覆盖另一种冲突样式?

更新时间:2022-04-29 21:54:23

首先,如果您不想让浏览器的历史记录干扰您的样式,请使用:visited伪类来匹配浏览器的样式.未访问的链接,然后只需根据您的数据库记录手动应用类.

First of all, if you don't want the browsers own history to interfere with your styles then use the :visited pseudo-class to match the style of the non-visited link, then just apply classes manually based on your DB records.

关于样式冲突,全部与选择器的特异性有关,如果两个具有相同属性的对象发生冲突(具有相同的特异性),则最后一个获胜".

Regarding conflicting styles, it's all about the specificity of the selector, and if two with the same properties conflict (have the same specificity) the last one "wins".

执行以下操作:

a:link, 
a:visited {
    font-weight: bold;
    color: black;
}

a.read {
    color: #444;
}