Forum Moderators: open

Message Too Old, No Replies

centred div different in IE and FF

         

jackvull

11:18 am on Jan 5, 2006 (gmt 0)

10+ Year Member



I have this code in IE, which works the way I want it to by centering the div. Unfortunately, this won't work in FF. ANy ideas?
Thanks

<html>
<head>
<title>Hello World</title>

<style type="text/css">
body
{
background-color: #039;
margin: 0 auto;
text-align: center;
}

td
{
font-family: Tahoma;
font-size: 10px;
color: 8B96A7;
font-weight: normal;
}

.defined
{
width: 775px;
height: 360px;
background-color:white;
font-family: tahoma;
font-size: 16px;
font-weight: normal;
color: black;
vertical-align: top;
padding:10px;
}
</style>

</head>
<body>

<div>
<table width="775" border="1" cellpadding="0" cellspacing="0" style="border-style: sold; border-color:black;">
<tr>
<td colspan="2">
<img src="a.gif" width="775" height="127" alt="">
</td>
</tr>
<tr align='center'>
<td colspan="2" bgcolor="CCCCCC" >

<a href="index.php" class="b"><font size="4">Home</font></a>&nbsp;&nbsp; ¦ &nbsp;&nbsp;
<a href="about.php" class="b"><font size="4">About us</font></a>&nbsp;&nbsp; ¦ &nbsp;&nbsp;
<a href="contact.php" class="b"><font size="4">Contact</font></a>
<br />
</td>

</tr>
<tr>
<td colspan="2" class ='defined'>
Hello World!

</td>
</tr>
<tr>

<td colspan="2" align="center" valign="top" bgcolor="CCCCCC" class="text3">
<br />
<a href="index.php" class="b">Home</a> ¦
<a href="about.php" class="b">About us</a> ¦
<a href="contact.php" class="b">Contact</a>
<br />
<font size='1'>Copyright </font>

<br /><br />
</td>
</tr>
</table>
</div>
</body>
</html>

Robin_reala

12:20 pm on Jan 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



text-align only works on inline objects. To centre block level objects we need to apply margins:

table { margin: 0 auto; )

IE6 gets this right if you're using a doctype but breaks and goes back to text-align if you're not.

If you want to centre the div directly then you'll need to give it a specific width, as divs by default fill all available horizontal space.