【问题标题】:CSS "text-decoration: none" does not seem to work [duplicate]CSS“文本装饰:无”似乎不起作用[重复]
【发布时间】:2021-04-09 12:03:39
【问题描述】:

StackOverflow 中有很多类似的问题,但我无法找到这个简单问题的答案。为什么下面的代码不能按预期工作?

<pre style="text-decoration: underline;">
underlined
underlined
<span style="text-decoration: none;">should NOT be underlined</span>
underlined
</pre>

【问题讨论】:

    标签: html css text-decorations


    【解决方案1】:

    display: inline-block 添加到span

    <pre style="text-decoration: underline;">
    underlined
    underlined
    <span style="text-decoration: none; display: inline-block">should NOT be underlined</span>
    underlined
    </pre>

    【讨论】:

    • 我为什么需要它?
    • 我不知道具体原因,但text-decoration 属性不适用于inline 元素,或者至少不能按预期工作。 span 元素的默认显示属性是inline,因此将其更改为inline-blockblock 通常可以解决它。我多次遇到这个问题,这就是我解决它的方法。
    • 单独设置display: inline-block;(并删除text-decoration: none;)也会删除span元素的下划线。这为这种奇怪的行为增添了另一个谜团!
    • 哇,确实如此。我会试着找到一些解释。
    • @FedonKadifeli 副本包含解释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    相关资源
    最近更新 更多