【问题标题】:Can't I override text-decoration to none? [duplicate]我不能将 text-decoration 覆盖为 none 吗? [复制]
【发布时间】:2012-06-18 07:11:56
【问题描述】:

可能重复:
How do I get this CSS text-decoration override to work?

Chrome 和 Firefox 正在密谋阻止我尝试使用直通文本装饰的 td,有时会被跨度禁用,如下所示:

<style type="text/css">
tr.st td {
  text-decoration: line-through;
}

tr.st td span.unstrike{
  text-decoration: none;
  background:yellow;
}

tr.st td span#unstrike-id{
  text-decoration: none;
  background:yellow;
}

tr.st td span.unstrike-important{
  text-decoration: none ! important;
  background:yellow;
}

</style>


<table  border>
    <tbody>
      <tr>
        <td>normal</td>
      </tr>
      <tr class="st">
        <td>struck out</td>
      </tr>

      <tr class="st">
        <td>struck out <span class="unstrike">unstrike class: shouldn't I be normal?</span></td>
      </tr>

      <tr class="st">
        <td>struck out <span id="unstrike-id">unstrike-id identifier.  Shouldn't I be normal?</span></td>
      </tr>

      <tr class="st">
        <td>struck out <span class="unstrike-important">unstrike-important: shouldn't I  be even more normal?</span></td>
      </tr>
    </tbody>
  </table>

我正盯着规范看,但我不明白。

文本修饰的特殊情况?什么给了?

演示here

【问题讨论】:

  • 哇,这很有趣,似乎text-decoration 被应用于整个 TD 的内容,而忽略了它下面的任何内容。没见过。
  • 查看这个答案:stackoverflow.com/a/1261974/698179 - 最好在所有tds 中放置span,并将样式单独应用为子元素。
  • 是的,我现在看到了,虽然我认为这是最好的先例:stackoverflow.com/questions/1823341/…

标签: css inheritance


【解决方案1】:

如果你有一个特定的顺序来使用属性,你可以使用:nth-child()

或者尝试将 line-decoration 添加到 span,而不是 td。看我的例子:jsfiddle

【讨论】:

    【解决方案2】:

    删除线应用于表格单元格,而不是其内容。类似的情况是对&lt;td&gt; 应用边框。删除 span 上的边框不会阻止 td 上的边框发光。

    你可以给 span 添加一个不透明的背景。


    添加:

    position: relative;
    display: inline-block;
    top: 0px;
    

    seems to fix it.

    【讨论】:

    • 我主要是从规范中寻找一些解释为什么会这样。有很多修复。你的绝对很有趣。但是,如果没有更深入地了解它的工作原理,以及为什么 inline-block 可以工作而普通块(比如 div)却不行,我会犹豫使用它。
    【解决方案3】:

    看起来这是几个问题的欺骗,特别是:

    How do I get this CSS text-decoration override to work?

    简而言之,http://www.w3.org/TR/CSS21/text.html#propdef-text-decoration 的(对我来说非常模糊)语言说“没有覆盖”。

    版主/编辑,请关闭我作为一个骗子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-20
      • 2012-07-13
      • 2017-04-11
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      相关资源
      最近更新 更多