Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cellpadding in one html table cell

Is it possible to have cell padding in just one cell versus the whole html table?

like image 637
leora Avatar asked Jul 22 '09 07:07

leora


People also ask

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

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 do cell spacing in a table?

The HTML <table> cellspacing Attribute is used to specify the space between the cells. The cellspacing attribute is set in terms of pixels. Attribute Values: pixels: It sets the space between the cells in terms of pixels.

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.

How do you use cell spacing and cell padding in HTML?

You can apply both padding and spacing, as in the fourth and fifth examples. In order to place space in or around each cell (or both), place the padding and/or spacing attributes within the <TABLE> code.


4 Answers

Just style the cell using CSS:

<table border='1'>
    <tr>
    <td style="padding: 50px;">cell1</td>
    </tr>
    <tr>
    <td>cell2</td>
    </tr>
</table>
like image 84
Curtis Tasker Avatar answered Oct 19 '22 05:10

Curtis Tasker


For use in styling an email it is sometimes hard to achieve padding with css if you want the mail to be consistent across email programs, especially Outlook. If you don't want to use css, a workaround is to put a whole new table with one row and one cell in the cell that you want to apply padding to. Then apply the padding to that 'one celled' table.

In the example given in the question this would become:

<table border='1'>
 <tr>
  <td>
   <table cellpadding="50">
    <tr>
     <td>cell1</td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td>cell2</td>
 </tr>
</table>
like image 37
C.A. Vuyk Avatar answered Oct 19 '22 07:10

C.A. Vuyk


Unfortunately not, if you're referring to using <table cellpadding="0">, as that is a table-wide setting. If you want padding to be applied to just one cell, you'll have to add a class and assign it a padding value that way.

like image 1
Bryan Veloso Avatar answered Oct 19 '22 06:10

Bryan Veloso


You can try this css.

Table using div

HTML

  <div class="divTable">
    <div class="divTableBody">
        <div class="divTableRow">
            <div class="divTableCell">1</div>
            <div class="divTableCell splcell">2</div>
            <div class="divTableCell">3</div>
        </div>
        <div class="divTableRow">
            <div class="divTableCell">4;</div>
            <div class="divTableCell">5</div>
            <div class="divTableCell">6;</div>
        </div>
    </div>
</div>

CSS

.divTable{
    display: table;
    width: 100%;
}
.divTableRow {
    display: table-row;
}
.divTableHeading {
    background-color: #EEE;
    display: table-header-group;
}
.divTableCell, .divTableHead {
    border: 1px solid #999999;
    display: table-cell;
    padding: 3px 10px;
}
.divTableHeading {
    background-color: #EEE;
    display: table-header-group;
    font-weight: bold;
}
.divTableFoot {
    background-color: #EEE;
    display: table-footer-group;
    font-weight: bold;
}
.divTableBody {
    display: table-row-group;
}
.splcell{
     background:red;
     color:#fff;
     font-weight:bold;
     text-align:center;
     padding: 5px;
}

using the class 'splcell' we can style the individual cell.

.splcell{
       background:red;
       color:#fff;
       font-weight:bold;
       text-align:center;
    } 
like image 1
Aswin KV Avatar answered Oct 19 '22 05:10

Aswin KV