Html 从锚点内的跨度中删除下划线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13856330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:21:50  来源:igfitidea点击:

Remove underline from span inside anchor

htmlcss

提问by Hommer Smith

I have this HTML:

我有这个 HTML:

<ul>
<li>
    <ul>
        <li>
            <a href="#"> <span> Test </span> Link </a>
        </li>
    </ul>
</li>
</ul>?

And this CSS:

这个CSS:

ul li ul li span {

    text-decoration:none;
}?

Why would the span inside the anchor still have underline?

为什么anchor里面的span还有下划线?

In other words: How would I get all the text underlined, exceptthe SPAN. Thanks

换句话说:除了SPAN之外,我如何让所有文本都加下划线。谢谢

回答by Mr. Alien

You need to target the anchor tagand not the span tagso use this

你需要定位anchor tag而不是span tag所以使用这个

ul li ul li a {
    text-decoration:none;
}?

Reason: text-decoration: underline;is applied to <a>tag by default browser stylesheet, so if you want to over ride it or if you want that none of the <a>tags on your website should have an underline than simply use this

原因:默认text-decoration: underline;应用于<a>浏览器样式表的标签,因此如果您想覆盖它,或者如果您希望<a>您网站上的任何标签都不应该有下划线,而是简单地使用它

a {
   text-decoration: none;
}

Edit: As I read your comment if you want your text to be underline except the text within <span>than use this

编辑:当我阅读您的评论时,如果您希望您的文本带有下划线,除了里面的文本<span>之外,请使用它

Demo

演示

ul li ul li a {
    text-decoration:underline;
}

ul li ul li a span {
    text-decoration:none;
    display: inline-block;
}

回答by Sowmya

Make tat spanin class as a

span在课堂上做 tat作为a

ais the tag which takes default underline since it is a link but not span. So whatever is inside the a tag takes the underline automatically.

a是采用默认下划线的标签,因为它是一个链接而不是span. 所以 a 标签内的任何内容都会自动带下划线。

ul li ul li a{
    text-decoration:none;
}?

DEMO

演示

回答by Animesh

It should be

它应该是

ul li ul li a {
text-decoration:none;
}
ul li ul li a:hover {
text-decoration:underline;
}

ul li ul li a span {
text-decoration:none;
display: inline-block;   
}

DEMO

演示

回答by Ruchira Shree

It should be

它应该是

ul li ul li a {

    text-decoration:none;
}?