Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table with spacing before/after separation line between rows

Tags:

html

css

sass

I'm trying to build a HTML table with separation line between rows. My main concern is mainly the fact I need to add a padding left/right in my tbody. I tried different things, such:

  • Add :before/:after floating element to add the space
  • Add border-collapse: collapse to the table, then add a border to the tbody, but I lost my border on the table doing that

Here is my table:

enter image description here

And this is what I need to do:

enter image description here

Codepen for the source: http://codepen.io/anon/pen/gojuw

Do you have any suggestion?

Thanks

like image 398
alexmngn Avatar asked Feb 13 '26 15:02

alexmngn


1 Answers

How about setting up a left and right border in the first and last <td>, respectively? See working example in here. It works something like this:

HTML:

<div id="table_wrapper">
    <table>
        <thead>
            <tr><td>Item 1</td><td>Item 2</td><td>Item 3</td></tr>
        </thead>
        <tbody>
            <tr><td>Item 1</td><td>Item 2</td><td>Item 3</td></tr>
            <tr><td>Item 1</td><td>Item 2</td><td>Item 3</td></tr>
            <tr><td>Item 1</td><td>Item 2</td><td>Item 3</td></tr>
        </tbody>
    </table>
</div>

CSS:

#table_wrapper {
    border: 1px solid #ddd;
}
table {
    border-collapse: collapse;
}
thead td {
    background-color: #eee;
}
thead td:first-child {
    border-left: 20px solid #eee;
}
thead td:last-child {
    border-right: 20px solid #eee;
}
tbody td {
    background-color: white;
}
tbody td:first-child {
    border-left: 20px solid white;
} 
tbody td:last-child {
    border-right: 20px solid white;
}
like image 170
dwitvliet Avatar answered Feb 15 '26 13:02

dwitvliet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!