Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't padding applied to table elements?

Tags:

html

css

This is more of a "tell me why it doesn't work" instead of "help me fix it" question. If I try to apply padding to a thead or tr element within a table, it doesn't work. The only way padding works is if I apply it directly to the th or td element. Why is this so? Is there an easy way to apply padding to the entire thead or tr or is adding it to the th and td the only option?

<table>
    <thead>
        <tr>
            <th>Destination</th>
            <th>Size</th>
            <th>Home Value</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>test 1</td>
            <td>test 2</td>
            <td>test 3</td>
        </tr>
    </tbody>
</table>

Notice the 10px of padding on the thead.

table {
    width: 100%;
}

thead {
    text-align: left;
    background-color: yellow;
    padding: 10px;
}

http://jsfiddle.net/5VQB7/

like image 567
Adam Robertson Avatar asked Mar 24 '13 06:03

Adam Robertson


People also ask

Does padding work on table?

In Tables, we can add padding to individual cells as well as specify space between different cells.

How do you put padding on a table?

Complete HTML/CSS Course 2022 Cell padding is the space between cell borders and the content within a cell. To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.

How do you add padding to a table cell in CSS?

You can easily set padding inside the table cells using the CSS padding property. It is a valid way to produce the same effect as the table's cellpadding attribute. Similarly, you can use the CSS border-spacing property to apply the spacing between adjacent table cell borders like the cellspacing attribute.

What is table padding?

The cell padding attribute places spacing around data within each cell. The cell spacing attribute places space around each cell in the table.


2 Answers

http://www.w3.org/TR/CSS2/box.html#propdef-padding

'padding'

Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column

like image 140
j__m Avatar answered Sep 28 '22 04:09

j__m


Try placing the padding in the th element instead. Typically you want to add padding to the th or td element, depending on the circumstance.

thead th {
  padding: 10px;
}
like image 20
Aiias Avatar answered Sep 28 '22 05:09

Aiias