这是一个转载的示例:
div.addu { color: #006e28; text-decoration: underline; }
div.addu blockquote pre { text-decoration: none; }
div.addu blockquote pre code { text-decoration: none; }
div.addu pre, div.rm pre, div.add pre { background-color: #f6f8fa; }
div.addu > blockquote {
border-left: 4px solid #00a000;
padding: 0 15px;
color: #006e28;
text-decoration: none;
}
<div class="addu">
<pre><code>Underline this code</code></pre>
<p><em>Effects</em>: Equivalent to:</p>
<blockquote>
<pre><code>Do not
Underline
This code</code></pre>
</blockquote>
</div>
带有下划线的早期代码看起来不错。带有左边框的blockquote看起来很棒。但是为什么内部代码仍带有下划线? text-decoration:none;
为什么不适用于它?如您所见,我试图在许多不同的地方添加它,但是顶级underline
似乎仍然存在。我该怎么做对呢?
答案 0 :(得分:3)
您可以使用>
的{{1}}选择器来实现此目的,
无需更改css
或添加课程
HTML
移除text-decoration
div.addu
选择器定位pre
标签并为其赋予>
text-decoration: underline
添加到text-decoration: underline;
标签
p
div.addu { color: #006e28; }
div.addu p { text-decoration: underline; }
div.addu > pre { text-decoration: underline; }
div.addu blockquote pre { text-decoration: none; }
div.addu blockquote pre code { text-decoration: none; }
div.addu pre, div.rm pre, div.add pre { background-color: #f6f8fa; }
div.addu > blockquote {
border-left: 4px solid #00a000;
padding: 0 15px;
color: #006e28;
text-decoration: none;
}
答案 1 :(得分:0)
您做对了,没有HTML解决方案,或者最快的解决方案就是在CSS中将这行display:inline-block
添加到div.addu blockquote pre code
规则,没有其他改变。
div.addu { color: #006e28; text-decoration: underline; }
div.addu blockquote pre { text-decoration: none; }
div.addu blockquote pre code { text-decoration: none; display:inline-block }
div.addu pre, div.rm pre, div.add pre { background-color: #f6f8fa; }
div.addu > blockquote {
border-left: 4px solid #00a000;
padding: 0 15px;
color: #006e28;
text-decoration: none;
}
<div class="addu">
<pre><code>Underline this code</code></pre>
<p><em>Effects</em>: Equivalent to:</p>
<blockquote>
<pre><code>Do not
Underline
This code</code></pre>
</blockquote>
</div>
由于text-decoration
仅适用于inline-block
元素,因此您可以这样做