Search code examples
htmlcsshtml-tablerowstrikethrough

Linethrough/strikethrough a whole HTML table row


After some research, I couldn't find an answer to this question. There was this but it didn't really answer my question. I would like to "strikethrough" a complete HTML table row in CSS, not just the text in it. Is it at all possible? From the example that I linked, it seems tr styling doesn't even work in Firefox. (And anyway, text-decoration only applies on text afaik)


Solution

  • Oh yes, yes it is!

    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