Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS padding for single TD inside a table

I have a table, constructed like this:

<table>
<tr>  <td>1</td>  <td>2</td>  <td rowspan="4">3</td></tr>
<tr>  <td>4</td>  <td>5</td>                        </tr>
<tr>  <td>6</td>  <td>7</td>                        </tr>
<tr>  <td>8</td>  <td>9</td>                        </tr>
<tr height="100"><td colspan="2">10</td><td class="eleven">11</td> </tr>
</table>

Now the problem is within the last row. Whole row has a height set to 100px, so there is a plenty of room in TDs. In the very last TD I want to set an individual padding, so only the content "11" is padded from the top:

.eleven {
    padding-top:15px;
}

Setting this causes the problem - the first TD in this row also gets padding-top:10px; Why and how to make only the 2nd one padded?

like image 754
wiktus239 Avatar asked Feb 09 '12 09:02

wiktus239


People also ask

How do you put padding inside a table?

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.

Can I put padding on TR?

You can't add padding or margins to a 'tr' they are simply a mechanism to separate cells into rows. If you want space in the cell then you add padding as Ryan suggested and if you want space between the border of each cell then you use border-spacing. e.g. That will give vertical spacing of 10px between rows.


1 Answers

Why don't you wrap the content you want to be padded into a <div> (onto which you will be applying the padding style) and put that <div> into the <td>?

<td>
    <div style="padding-top: 15px;"> 
        Content 
    </div> 
</td>
like image 128
Navneeth G Avatar answered Sep 22 '22 10:09

Navneeth G