好的,我得到了它下面样式的链接
a:link, a:visited {
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: green;
color: white;
}
这对所有普通链接都有好处
但是,对于这个特定的链接,我不希望它继承其当前默认样式的任何内容。我希望它使用其他样式,所以我使用了 id 选择器
#otherLink, #otherLink:visited {
color: blue;
text-decoration:none;
font-weight: bold;
}
#otherLink:hover, #otherLink:active {
color: red;
}
然后我设置
var userName_a = document.createElement('a');
userName_a.setAttribute( 'id', 'otherLink' );
问题是 otherLink
的某些样式受到了 userName_a
的影响,但其他当前默认链接样式仍然影响 userName_a
。
那么,如何让一个特定的链接不受当前默认样式的影响呢?
最佳答案
清除属性的唯一方法是在辅助选择器中将它们重新声明为初始值,即 background-color:initial;
关于javascript - 如何使特定链接不受其当前默认样式的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35006629/