Search code examples
htmlcsshtml-tablemarkupw3c

How to get text flush to top/bottom of a table cell


I have a table cell with text in it but how can I make the text flush to the top or bottom of the cell (with no padding above it)? I've tried vertical-align, but it's still not quite to the top 'edge'.

My code

<table>
    <tr>
        <td class="foo">3.2325</td>
        <td class="bar">4.5931</td>
    </tr>
</table>

table {
    border-bottom: 2px solid black;
    border-collapse: collapse;
}
table td {
    border-top: 1px solid black;
    border-collapse: collapse;
    background-color: pink;
    padding: 0 10px 10px;
}
.foo {
    font: bold 30px arial;
    border-right: 1px solid black;
    vertical-align: top;
}
.bar {
    font: normal 16px arial;
}

JSfiddle example: http://jsfiddle.net/KznxN/2/


Solution

  • depending on whether you wish more above or below, you adjust the "line-height" depending

    example:

    . {foo
         font: bold 30px arial;
         border-right: 1px solid black;
         vertical-align: top;
         line-height: 24px;
    }
    

    But beware, it would be better fix the height size of your cell