The reason IE7 was centering your table (which is a block element) with the body’s “text-align: center” is because you are in Quirks Mode-- where IE7 is acting like IE5 (what your grandma used to use back in the 90’s). To correct this, you’ll need a Doctype on your page.
Then setting a width on your table and using margin: 0 auto in the css will center your table (any block can be centered with this technique).
Now you are nesting tables-- a Bad Thing, generally. But ok. Let’s look.
But the blue table is still in the center inside of the pink table
although I wrote text-align:left;
Text-align… aligns inlines such as text. Why would you try to align a block like a table with text align? Text align aligns text. Besides, in your CSS (in your style tag) you’ve said, ALL tables, center:
table {
text-align: center;
margin: 0 auto;
}
This means all tables, not just the first one.
Tables have slightly different rules than other blocks, but removing all the “text-aligns” you have in your html, you could center the pink table on the page and let the blue table stay to the left (which is a default usually).
Give the pink table an id.
<table id=“pink”>
In your CSS, you can set a width on the pink table and center it with margin: 0 auto; the 0 means no top or bottom margin, and auto refers to the sides.
#pink {
width: 700px;
margin: 0 auto;
}
But none of this will work in IE if you let it stay stupid. Use a doctype, and use it properly.
Your table is centred in all browsers except IE because you don’t have a doctype. Without a doctype IE reverts to quirks mode and behaves more like ie5 and doesn’t understand auto margins.
You must always have a valid doctype.
Here is the page centred in every browser including ie5 -8.
The question doesn’t make a lot of sense as the pink table is inside the yellow cell that contains it.Do you have other content in that yellow cell apart from the table? You could float the table to the right assuming there’s room inside the cell which would mean the inner table would need a smaller width than the cell otherwise it will just be 100% width.
Why don’t you use 2 cells with different colours?
I can’t really work out what you want for the above so you may need to go into more detail as to what you are trying to do exactly:)