文字修饰:无; 不适用于一个简单的例子

Har*_*iec 2 html css css3 text-decorations

我很好,为什么"Should not be underlined"在下面的代码中仍有下划线的字样:

<html>
<head>
<style type="text/css">
.badge1-link { text-decoration: none; }
.badge1 { text-decoration: underline; }

.badge2-link {text-decoration: underline;}
.badge2 {text-decoration: none;}

</style> 
</head>
<body>
<a href="#" class="badge1-link"><span class="badge1">Underlined</span> | not underlined</a>
<br/>
<a href="#" class="badge2-link"><span class="badge2"> Should not be underlined</span> | Underlined</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Cla*_*ton 5

一旦锚标记被赋予下划线,就不能像你建议使用badge2那样被部分删除

请看链接:从链接中删除顽固的下划线.接受的答案有一些评论说明相同.

您的问题的解决方案是从锚标记中删除下划线,然后像使用badge1一样添加部分下划线


Las*_*ith 5

display:inline-block可以解决问题。它对我有用。改变你的风格如下

.badge2 {display:inline-block;text-decoration: none;} 
Run Code Online (Sandbox Code Playgroud)