views:

75

answers:

6

I have an html page :

<html>
<head>
<title>
All Time Set Window
</title>
</head>
<body>
<div align="center" style="width:1000px; height:100%; margin-left:auto; margin-right:auto;">
    <div style="width:100%; height:20%; background-color:#F8E0E0; float:top;">
        <div align="center">This is Header</div>
    </div>
    <div style="width:100%; height:60%; background-color:#F5F6CE;">
        <div align="center" style="width:70%; background-color:#E3F6CE; float:left;">This is Left Frame</div>
        <div align="center" style="width:30%; background-color:#E0E0F8; float:right;">This is Right Frame</div>
    </div>
    <div style="width:100%; height:20%; float:bottom; background-color:#F8E0E0;">
        <div align="center">This is Footer</div>
    </div>
</div>
</body>
</html>

I have used Margin-left & Margin-right to auto for taking div to center. This is working in Mozilla & not in Explorer. What is solution for the same.

A: 

you need to add auto to your margin

<div style="margin:10px auto;width:100px;">stuff</div>

This div will be centered because of the auto attribute.

Sam
A: 
margin:0px auto;

an you'd have to specify a width

pleasedontbelong
A: 
#yourdiv
{
 position:absolute;
 left: 50%; 
 width: 700px;
 margin-left: -350px;
 top: 50%;
 height: 400px;
 margin-top: -200px;
}

The properties left, width and margin-left are for horizontal alignment, and the top, height and margin-top for the vertical one. If you put all of them, you will have a div perfectly centered in your page.

Squ36
A: 

For internet exxplorer you can set a text-align center on your body, and on your div text-align: left.

That should do the trick ;-)

joggink
+1  A: 

The correct solution (according to the spec) is the one you have. You should set both margins to auto to center the block.

But as usual, explorer does not play by the rules. To make it center a block you have to set text-align of the parent element to center. Since you probably don't want all the text in your element itself to be centered as well, you'll have to negate the behaviour again by setting text-align to left on that one.

<html>
  <head>
    <title>All Time Set Window</title>
  </head>
  <body>
    <div style="text-align:center">
      <div align="center" style="width:1000px; height:100%; margin-left:auto; margin-right:auto; text-align:left">
        <div style="width:100%; height:20%; background-color:#F8E0E0; float:top;">
          <div align="center">This is Header</div>
        </div>
        <div style="width:100%; height:60%; background-color:#F5F6CE;">
          <div align="center" style="width:70%; background-color:#E3F6CE; float:left;">This is Left Frame</div>
          <div align="center" style="width:30%; background-color:#E0E0F8; float:right;">This is Right Frame</div>
        </div>
        <div style="width:100%; height:20%; float:bottom; background-color:#F8E0E0;">
          <div align="center">This is Footer</div>
        </div>
      </div>
    </div>
  </body>
</html>
Joeri Hendrickx
A: 

is this what you looking for?

<html>
<head></head>
<body>
    <center>
        --- olalala place your content here ---
    </center>
</body>
</html>
GusDe CooL
Not working. And <center> is for text only but not for div...
Sarang
check it here, i test it with FF3.6 and IE6.http://dimatadesign.com/app/a.html
GusDe CooL