text-align and Netscape

S

shank

Is there a reason why text-align:center would not work with NS 7.1 ? I have
text-align:center on the body tag that works fine for centering <DIV> and
<TABLE> in the body in IE. But NS shows those objects as being left aligned.

What do I need to change?
 
P

PeterMcC

Is there a reason why text-align:center would not work with NS 7.1 ?
I have text-align:center on the body tag that works fine for
centering <DIV> and <TABLE> in the body in IE. But NS shows those
objects as being left aligned.

What do I need to change?

It's Netscape that gets it right, the correct method is to set the margins,
left and right, to auto.

Because IE 5x and 6 in quirks mode don't implement this, the
text-align:center is used for them. You can combine the two methods. Auto
margins for compliant browsers and the text-align:center for IE5x. You have
to remember to left align the text in anything that inherits the centering
where it's inappropriate.

Have a look at:
http://bluerobot.com/web/css/center1.html
 
S

Steve Pugh

shank said:
Is there a reason why text-align:center would not work with NS 7.1 ? I have
text-align:center on the body tag that works fine for centering <DIV> and
<TABLE> in the body in IE. But NS shows those objects as being left aligned.

Because Netscape gets CSS right and IE doesn't.

text-align: center; should center inline content, not blocks or tables
themselves.

Use margin-left: auto; and margin-right: auto; to center blocks in
standards compliant browsers. Keep on using text-align: center; for
IE5 but remember to add text-align: left; on the child elements so
that the text within those elements is not centered.

Steve
 
L

Leif K-Brooks

shank said:
Is there a reason why text-align:center would not work with NS 7.1 ? I have
text-align:center on the body tag that works fine for centering <DIV> and
<TABLE> in the body in IE. But NS shows those objects as being left aligned.

IE is broken and centers block-level elements with text-align. Put
margin:auto on the block-level elements instead.
 
D

DU

shank said:
Is there a reason why text-align:center would not work with NS 7.1 ? I have
text-align:center on the body tag that works fine for centering <DIV> and
<TABLE> in the body in IE. But NS shows those objects as being left aligned.

What do I need to change?

Everyone told you that MSIE gets it wrong but MSIE 6 for windows in
standards compliant rendering mode gets it right by supporting
margin:0 auto;
accordingly.
So the first thing to do is to trigger standards compliant rendering
mode in MSIE 6 for windows and you'll not have to write any
cross-browser code to center block-level elements and/or to center
inline elements in the table (text-align is a CSS1 property inherited
and inheritable) or within any block-level elements.

MSIE 6 for windows supports both margin:0 auto and
text-align:left|center|right according to W3C CSS1... as long as the
document triggers standards compliant rendering mode.

DU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top