使用:any-link选择器而不是a元素来匹配超链接。a标签作为选择器的问题在于,它匹配所有<a>元素,即使是那些并没有href属性的a元素,也不是超链接。:any-link仅匹配有超链接的<a>元素。Web浏览器在其用户代理样式表中也使用:any-link而不是a。
/* OPTION A */
header :any-link {
text-decoration: none;
}
header :any-link:hover {
text-decoration: underline;
text-decoration-thickness: 0.08em; /* set thickness again */
}
/* OPTION B */
header :any-link {
text-decoration: none;
}
header :any-link:hover {
text-decoration: underline 0.08em; /* set both line and thickness */
}
/* OPTION C */
header :any-link {
text-decoration-line: none;
}
header :any-link:hover {
text-decoration-line: underline;
}