![]() If you need to center several tables the same way, use a class instead of an id.Good idea! I like the concept of this article and also the show/hide structure. Unfortunately, "text-align: center" will center all the text inside your table cells, but we counter that by setting "tr" and "td" to align left. "text-align: center" is there for Internet Explorer, which won't work without it. ![]() Set "width:100px" to whatever width you need. If you want your table to be of fixed width, define your CSS like this: If you had many tables on a page that you wanted to be the same width and centered, you would do this in your CSS: Note that I was using an id to describe the table. If you want your table to be a certain percentage width, you can do this:Īnd then in your HTML/XHTML, you would do this: Internet Explorer 5.5 and up, however, needs you to add this to your CSS as well: To center a table, you need to set the margins, like this:Īt this point, Mozilla and Opera will center your table. Why? Because "text-align" applies to inline content, not to a block-level element like "table". The table itself will be left-aligned, but all the content in the table cells will be centered. ![]() The obvious way might appear to use the CSS "text-align: center " somewhere, maybe like one of these: However, it's not so obvious how to center a table using CSS. The "align" attribute has been deprecated, however, in favor of CSS (Cascading Style Sheets), and this is a good thing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |