Jump to content

Centering Tables With Css


Recommended Posts

Okay...I decided to try and go for xhtml strict, and now I need to know how to center tables with CSS. I can center content (text) but not the physical tables. Stupid strict filtering stuff and it not allowing you to use the align="center" attribute. :( And I refuse to use <center>. For whatever means. I don't like that tag.


You can see my attempt at at trying to align this calendar here:



The code I used was, put simply, like this:

>Inside the page:

<div class="center"><table><tr><td>Content</td></tr></table></divide>

The css for center:

.center {text-align: center;}

Link to comment
Share on other sites

Hi Daniel.

In addition to the DIV centering its text, you need to apply a little css to the TABLE itself. Try this:


<div class="center">

<table id="centered">





.center { text-align: center; }

#centered { margin: 0 auto; }


Very brave of you to go straight for XHTML Strict. Good for you, and good luck.

Link to comment
Share on other sites

Daniel, try this:

><table class="center"><tr><td>Content</td></tr></table>

.center { width: 700px; margin-left: auto; margin-right: auto; }

No need to use <div> :(

And of course, you can change the 700px to whatever you want the table's width to be :)

Link to comment
Share on other sites

Ah, thank you both very much. :wallbash: Also, is there any substitute for making a page open in a new window with the target="_blank" (or target="new", or someting, I don't remember what the other way to do it is since I only use the first way)?


If not, I'll use javascript, but there must be some way around this...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...