Forum Moderators: not2easy

Message Too Old, No Replies

centering objects

         

nwall

9:27 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



while i'm here i guess i'll go ahead and ask about something that's been bugging me. 'text-align' doesn't seem to effect objects on firefox, so is there a way to align an object with CSS? here's some code that shows a child div that doesnt center align in firefox, while it does in IE:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
     #A {width: 300px; border: 1px solid #000000; text-align: center}
     #B {border: 1px solid #ff0000; width: 100px}
</style>
</head><body>
     <div id="A">
          <div id="B">test</div>
     </div>
</body></html>

up until now i have been fixing this using conventional HTML (align="center"):


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
     #A {width: 300px; border: 1px solid #000000}
     #B {border: 1px solid #ff0000; width: 100px}
</style>
</head><body>
     <div id="A" align="center">
          <div id="B">test</div>
     </div>
</body></html>

is there a way to acheive this using CSS or is HTML the best way to go about it?

createErrorMsg

9:52 pm on Mar 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



'text-align' doesn't seem to effect objects on firefox, so is there a way to align an object with CSS?

In FF, text-align:center only works to center text in inline-boxes. To center a block level element it needs two things: a width, and an auto left/right margin. Add the following to your #B div...

margin:0 auto;

Make sure you leave the text-align:center;, however, as pre-version6 IE browsers do not support the auto-margin method.

cEM