在 Chrome 和 Firefox 上,如果我在一个标签上应用了 text-decoration:underline 样式,那么默认情况下下划线不会应用到伪元素上。 但是在 IE 中,它会应用到伪元素上,而且我无法去掉它。 我希望链接有下划线,但是伪元素没有。
如果我添加一个 span 元素并将下划线添加到它上面,它就能正常工作,但我想知道是否可以在没有额外标记的情况下实现。
a{
padding-left: 9px;
position:relative;
display:inline-block;
}
a:before{
content:'\203A\00a0';
position:absolute;
top:0;
left:0;
display: inline-block;
}
#underline{
text-decoration: none;
}
#underline:hover{
text-decoration:underline;
}
/* special for IE */
#underline:hover:before
{
text-decoration:none !important; /* does nothing ! */
}
#color{
color:green;
}
#color:hover{
color:red;
}
#color:hover:before{
color:green; /* work ! */
}
#span{
text-decoration: none;
}
#span:hover span{
text-decoration: underline;
}
<a href="#" id="underline">underline</a>
<br>
<a href="#" id="color">color</a>
<br>
<a href="#" id="span"><span>with span</span></a>