Horizontally align table rows
Is it possible to horizontally align table rows?
What most people will say: "Why do you start a new row if you want the cells to align horizontally?"
My anwser: "I can't control the table structu开发者_JS百科re. I just can't, okay?"
Code:
tr {
display: inline;
}
This looks fine in FireFox, but Internet Explorer 7 aligns the rows vertically. I would prefer not to use JavaScript.
EDIT: Before you start JavaScript-hacking, I already came up with something like this:
String.prototype.replace.call(table.innerHTML,/<\/tr>.*<tr>/,"")
What about this?
Code:
table tr { display: table-cell; };
Hope I helped.
Try using float:left;
instead of displaying it inline
.
If you want to center the content of tr
then write it as
tr {width:100%, text-align:center}
If you want to give an exact width and center the whole table, then do this:
table {width:100px (exact width), margin:0 auto; text-align:center}
If you are having an issue with alignment float:left;
will fix it.
精彩评论