Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical-align:text-top; not working in table cell (td) in HTML5

Tags:

html

Not sure why but for the life of me I cannot get my text to align on the top of a table cell (td) when the cell before it is wrapping text.

If I write it out in the HTML it works, but unable to get the same effect in my CSS.

Works with HTML:

<td style="vertical-align:text-top;">Some Text</td>

Doesn't with CSS:

table td { vertical-align: text-top; }

And I have tried every combination you can think of within my CSS

like image 727
4michaelcoleman Avatar asked Sep 28 '12 00:09

4michaelcoleman


People also ask

How do I align text to the top of a table cell in HTML?

To place an item at the top or bottom of its cell, insert the "VALIGN=" attribute within the code for that cell. To vertically align an entire row (e.g., placing all data in that row at the tops of the cells), insert the "VALIGN=" attribute within the code for that row.

How do I align text to the top in HTML?

HTML | <td> valign Attribute The HTML <td> valign Attribute is used to specify the vertical alignment of text content in a cell. Attribute Value: top: It sets the content to top-align. middle: It sets the content to middle-align.


1 Answers

Make sure you are not setting "display: block" on the TD elements, as vertical align doesn't work on block elements. Also, text-top is not the best, and has some cross browser issues. Use "top" instead. Try adding this in your stylesheet:

table td { 
  display: table-cell;
  vertical-align: top; 
}
like image 77
Ryan Wheale Avatar answered Oct 14 '22 18:10

Ryan Wheale