Renegade605 Posted November 6, 2008 Share Posted November 6, 2008 Hi all, in my website I use numerous divs and a few tables, none of which are centered as they should be in Firefox. (They do work in IE)The best/biggest example of this is the entire content div (the on with the green bars on the sides). They are centered in IE because of the CSS code that follows. <html><head><style type="text/css">body, div.center { text-align: center; }</style></head><body><div> <!-- This div should be centered --><p>text</p><div class="center"><table> <!-- This should also be centered --> </table></div></div></body></html> That makes the divs/tables centered in IE, but not FF.How can I center them in FF as well? Link to comment Share on other sites More sharing options...
jeffman Posted November 6, 2008 Share Posted November 6, 2008 Sure, it works in IE, but what you're using is an IE workaround, not the preferred CSS method. Text-align centers content, ideally text content. To really make the workaround work, your declaration should be for BOTH the body and html elements, thus: /* The IE workaround: */body, html { text-align: center;}/* To make elements center on their own, adjust the margin: */div.center { margin: 0 auto;} The second works in all standards-compliant browsers. Link to comment Share on other sites More sharing options...
Renegade605 Posted November 6, 2008 Author Share Posted November 6, 2008 Excellent, thank you it works.I assume it's still okay to leave the text-align property for text only elements such as <p> and <td>? Link to comment Share on other sites More sharing options...
Synook Posted November 6, 2008 Share Posted November 6, 2008 Text-align should be used to center text. Use automatic margins to center children. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.