如何相对于某个父标记禁用CSS样式?

如何相对于某个父标记禁用CSS样式?,css,html,Css,Html,这是我的HTML: <!DOCTYPE html> <html> <style>span {text-decoration: none}</style> <body> <a href="#">underscored text <span>without underscore</span></a> </body></html> span{文本装饰:无} 仍保留下

这是我的HTML:

<!DOCTYPE html>
<html>
<style>span {text-decoration: none}</style>
<body>
<a href="#">underscored text <span>without underscore</span></a>
</body></html>

span{文本装饰:无}

仍保留下划线。可能的解决方法是什么(不使用JavaScript,也不更改HTML)?

将其设置为锚点标记没有下划线,但跨度确实有下划线

<a href="#"><span>underscored text</span> without underscore</a>

a{
  text-decoration:none;
}

a span{
  text-decoration:underline;
}

a{
文字装饰:无;
}
跨度{
文字装饰:下划线;
}
试试这个

<!DOCTYPE html>
<html>
<style>span {text-decoration: none;display: inline-block;}</style>
<body>
<a href="#">underscored text <span>without underscore</span></a>
</body></html>​

span{文本装饰:无;显示:内联块;}
​
链接至原始答案:


我认为没有办法,所以这里有一个肮脏的黑客:

<html>
<style>
    span {border-bottom:1px solid white;}
    a {text-decoration: none;border-bottom:1px solid blue;}
    </style>
<body>
<a href="#">underscored text <span>without underscore</span></a>
</body></html>​

span{边框底部:1px纯白;}
a{文本装饰:无;边框底部:1px纯蓝色;}
​

。。。只是因为你提到你不能更改HTML。

我不能更改HTML,只有CSSRefer是的,这就是为什么我给了原始答案的链接:)原因已经解释了,如果有人感兴趣的话