Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the HTML5 equivalent to the align attribute in table cells?

Tags:

html

css

I'm refactoring an old site, and that maze is full of tables. We're moving to HTML5 and I need to fix a table full of

<td align="center"> 

code. I found a partial solution by creating a class

.centered {     text-align: center; } 

and assigning it to every TD containing text.
But this is not working on images and some other elements.

margin: auto; 

won't work either.
What's the fastest way to center ALL content inside a TD?

like image 502
Alan Piralla Avatar asked Jun 07 '13 13:06

Alan Piralla


People also ask

What is align in HTML5?

The purpose of the HTML align attribute is to specify the alignment of data and the justification of text in a cell of a table. Supported elements. HTML align attribute supports col, colgroup, tbody, td, tfoot, th, thead, tr elements. Usage of align attribute for any other HTML elements is deprecated.

Does HTML5 support align attribute?

The align attribute of <object> is not supported in HTML5. Use CSS instead. For an object to align middle, top, or bottom use the CSS property vertical-align. For an object to align left or right use the CSS property float.

How do you align cells in a table 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.

What is table align in HTML?

The align attribute specifies the alignment of a table according to surrounding text. Normally, an HTML table will have a break before and after it. The align attribute allows other HTML elements to wrap around the table.


1 Answers

If they're block level elements they won't be affected by text-align: center;. Someone may have set img { display: block; } and that's throwing it out of whack. You can try:

td { text-align: center; } td * { display: inline; } 

and if it looks as desired you should definitely replace * with the desired elements like:

td img, td foo { display: inline; } 
like image 75
Bill Criswell Avatar answered Sep 21 '22 22:09

Bill Criswell