Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

centering a div with css?

Doing things this way, it works exactly how I want it to for chrome and firefox, but doesn't work for IE for some reason. Any ideas?

#windowWrapper

{

margin-left: auto;

margin-right: auto;

width: 800;

}

Update:

Ron: I did the same thing as you mentioned, just in a slightly different way. The problem is that it doesn't work with Internet Explorer for some reason, but works perfectly with other browsers.

Update 2:

Nick: Position: Center doesn't do anything... I'm using floats if that makes any difference.

4 Answers

Relevance
  • Anonymous
    9 years ago
    Favorite Answer

    You can not use floats and expect content to center. I've used those CSS rules for years and IE has never given a problem except those before IE 6. I just checked those rules again in IE and they worked perfectly.

    Floats removes the floated content from the normal document flow.

    #windowWrapper {

    width: 800px;

    margin: 0 auto;

    }

    Centering:

    Centering an element requires setting a width to the exact width of the content, using a proper document type and using the CSS property: margin: 0 auto; This is done in the CSS that styles the element. Example:

    body {

    width: 90%;

    height: 600px; /* optional */

    margin: 0 auto;

    background: #fff url(path to non-tiled image) no-repeat center scroll;

    }

    Example as a Class:

    .selector_name {

    width: 90%;

    height: 600px; /* optional */

    margin: 0 auto;

    background: #fff url(path to non-tiled image) no-repeat center scroll;

    }

    HTML for Class: <div class="selector_name">Content here</div>

    Example as an ID:

    #selector_name {

    width: 90%;

    height: 600px; /* optional */

    margin: 0 auto;

    background: #fff url(path to non-tiled image) no-repeat center scroll;

    }

    HTML for Class: <div id="selector_name">Content here</div>

    Change parameters as you need. Set "#fff" to background color you want. Set "scroll" to "fixed" if you want page contents to scroll over background image. CSS was given for an image that does not tile. Doesn't have to be the body tag, but you should get the idea.

    Ron

  • ?
    Lv 4
    5 years ago

    I have no idea what you have got used to core it to this point, however as it is a box / wrap the fine technique to core it horizontally could be so as to add the next in your CSS: #box { margin: vehicle; } This will make certain that that div and the whole thing within shall be horizontally based in any browser. Try it out and notice. If that does not paintings, let us know your approach to this point so we will determine it out.

  • 9 years ago

    #windowWrapper {

    width: 800px;

    height: 100%:

    position: center;

    }

  • <div align="center">content here</div>

Still have questions? Get your answers by asking now.