简体   繁体   English

如何删除伪元素上的下划线?

[英]How to remove an underline on a pseudo-element?

On Chrome and Firefox, if I apply a text-decoration:underline on a tag, by default the underline does not apply to the pseudo element.在 Chrome 和 Firefox 上,如果我在标签上应用 text-decoration:underline,默认情况下下划线不适用于伪元素。 But on IE it does, and I can't remove it.但在 IE 上确实如此,我无法删除它。 I want the link to be underlined, but not the pseudo element.我希望链接带有下划线,而不是伪元素。

It work if I add a span inside and put the underline on it, but I want to know if it can be made without additional markup.如果我在里面添加一个跨度并在其上加上下划线,它会起作用,但我想知道它是否可以在没有额外标记的情况下进行。

 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>

It seems that IE don't let you override the text-decoration in the pseudoelement if it isn't set in it. 似乎IE不允许你覆盖伪元素中的文本修饰,如果它没有在其中设置。 First let the pseudo-element be underlined - text-decoration: underline - and afterwards override this with textdecoration: none. 首先让伪元素加下划线 - 文本修饰:下划线 - 然后用textdecoration:none覆盖它。

 #underline:hover:before { text-decoration:underline; } #underline:hover:before { text-decoration:none; } 

As text-decoration: underline; 作为text-decoration: underline; can't be overridden in IE you could use border-bottom: 1px solid green; 不能在IE中覆盖你可以使用border-bottom: 1px solid green; instead. 代替。 This can then be overwritten on the :before by setting its border colour to the background colour (in this case white). 然后可以在覆盖:before通过其边框颜色设置为背景色(在这种情况下,白色)。 This will only work on solid colour backgrounds though. 这只适用于纯色背景。

 a { color: green; display: inline-block; padding-left: 9px; position: relative; text-decoration: none; } a:before { content: '\\203A\\00a0'; display: inline-block; left: 0; position: absolute; top: 0; } a:hover { border-bottom: 1px solid green; } a:hover:before { border-bottom: 1px solid white; } 
 <a href="#" id="underline">Hover to check underline</a> 

you can add this to your css. 你可以把它添加到你的CSS。 this helped me in the IE 这帮我在IE中

a {text-decoration:none;}
a:hover {text-decoration:underline;}
a:before,a:after { text-decoration:underline;}
a:before,a:after,
a:hover:before,a:hover:after {text-decoration:none;}
a:link { text-decoration: none; }


a:visited { text-decoration: none; }


a:hover { text-decoration: none; }


a:active { text-decoration: none; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM