划线/删除线穿过整个 HTML 表格行

新手上路,请多包涵

经过一些研究,我找不到这个问题的答案。有 这个,但它并没有真正回答我的问题。我想在 CSS 中“删除”一个完整的 HTML 表格行,而不仅仅是其中的文本。有可能吗?从我链接的示例来看,似乎 tr 样式甚至在 Firefox 中都不起作用。 (无论如何,文字装饰只适用于文字afaik)

原文由 Mathieu M-Gosselin 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 833
2 个回答

哦,是的,是的!

CSS:

 table {
    border-collapse: collapse;
}

td {
    position: relative;
    padding: 5px 10px;
}

tr.strikeout td:before {
    content: " ";
    position: absolute;
    top: 50%;
    left: 0;
    border-bottom: 1px solid #111;
    width: 100%;
}

HTML:

 <table>
    <tr>
        <td>Stuff</td>
        <td>Stuff</td>
        <td>Stuff</td>
    </tr>
    <tr class="strikeout">
        <td>Stuff</td>
        <td>Stuff</td>
        <td>Stuff</td>
    </tr>
    <tr>
        <td>Stuff</td>
        <td>Stuff</td>
        <td>Stuff</td>
    </tr>
</table>

http://codepen.io/nericksx/pen/CKjbe

原文由 crinkledMap 发布,翻译遵循 CC BY-SA 3.0 许可协议

我的回答(下)说这是不可能的。正如@NicoleMorganErickson 所指出的,我错了。请查看她的回答(并点赞!)了解如何操作。简而言之,您使用 :before 伪类来创建一个元素,该元素在内容上方的单元格中间绘制边框:

 table           { border-collapse:collapse } /* Ensure no space between cells   */
tr.strikeout td { position:relative        } /* Setup a new coordinate system   */
tr.strikeout td:before {                     /* Create a new element that       */
  content: " ";                              /* …has no text content            */
  position: absolute;                        /* …is absolutely positioned       */
  left: 0; top: 50%; width: 100%;            /* …with the top across the middle */
  border-bottom: 1px solid #000;             /* …and with a border on the top   */
}


(原答案)

不,不可能只使用 CSS 和语义表标记。正如@JMCCreative 所建议的那样,可以使用多种方式在 视觉 上将一条线放置在您的行上。

I would instead suggest using a combination of color , background-color , font-style:italic and/or text-decoration:line-through to make the entire row obviously different. (我个人会强烈地将文本“淡化”为比普通文本更接近背景的颜色,并将其设为斜体。)

原文由 Phrogz 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏