2

Im a newbie in css and Im having trouble centering two divs. I have a 1920 x 1080 screen resolution and using margin will not center the two divs if the visitor of my website have lower resolution. I know it will moved, right?

Details:

Please take a look at my problem here ---> http://i1204.photobucket.com/albums/bb409/bendaggers/help.png

  • Div id = Topwrapper
  • Div id = MainWrapper: holds the container and sidebar (gray)
  • Div id = Container (yellow green)
  • Div id = Sidebar (blue)

I have no problem with the Topwrapper, as you can see, it is in the center position but my very big problem is the Container and Sidebar. I cant align it with the Topwrapper. can you help me code? Another thing, can you please consider the screen resolution, as far as i know, my Mainwrapper code will adjust its width because of the min-width=1000px;

If you think you have a better idea with my codes, please feel free to revise it.

    <div id="TopWrapper"></div>
    <div id="MainWrapper">

        <div id="Content"></div>
        <div id="Sidebar"></div>

    </div>

#MainWrapper {
    height:3000px;
    min-width:1000px;
    background-color:#CCC;

}

#TopWrapper {
    background-image:url(images/topwrapper.png);
    background-repeat:no-repeat;
    background-position: center bottom;
    min-width:100%;
    height:77px;
    margin: 0;
}

#Content {
    height:3000px;
    min-width:630px;
    background-color: #0F0;
    float:left;
    margin-left:150px;
    display:inline;


}

#Sidebar {
    height:3000px;
    min-width:350px;
    background-color: #00F;
    margin-left:20px;
    float:left;
    display:inline;
}

Thank you very much in advance!

Ben Daggers
  • 1,000
  • 1
  • 16
  • 51

3 Answers3

0

Try this:

#MainWrapper {
    height:3000px;
    width:1000px;
    background-color:#CCC;
    margin:0 auto;

}

#TopWrapper {
    background-color:#000000;
    min-width:100%;
    height:77px;
    margin: 0;
}

#Content {
    height:3000px;
    width:630px;
    background-color: #0F0;
    float:left;


}

#Sidebar {
    height:3000px;
    width:350px;
    background-color: #00F;
    margin-left:20px;
    float:right;
}

If this isn't what you're looking for, let me know. I'll be happy to work with you.

Oh, and if you want the background to be a certain colour, just add:

    body {
    background-color:#CCC; /* or whatever colour you like */
}
stefmikhail
  • 6,877
  • 13
  • 47
  • 61
  • i have simple objective. I want the topwrapper, maincontainer, content & sidebar with 1000px width placed in the center no matter the resolution of the page viewer. my problem is mainwrapper, content and sidebar is not lining up with topwrapper. – Ben Daggers Aug 29 '11 at 05:36
  • @user917151 - So are you saying the maximum width will be 1000px? – stefmikhail Aug 29 '11 at 05:40
  • yes, i think thats what i want to achieve. 1000 width, center in the page. – Ben Daggers Aug 29 '11 at 05:45
  • @user917151 - I will amend my answer above with an example. Give it a try and tell me how it goes. – stefmikhail Aug 29 '11 at 05:48
  • @user917151 - Anytime! Glad it worked. If you have any questions about why it worked, let me know. And don't forget to accept your answers and vote! It's good for everyone! – stefmikhail Aug 29 '11 at 06:06
  • for now, i will try to understand your code so that i will learn something for myself. Glad you bumped in to my question. Thank you very much. – Ben Daggers Aug 29 '11 at 06:12
0

You can style the existing div "#MainWrapper" with a width that complements the two divs with content already in them, making sure there is space between both of them and leave room for margins on both sides (maybe 30px wider than the sum of the two divs), and then give "margin-left:auto;" and "margin-right:auto;" to the div #MainWrapper so it centers itself. You would then need to style the "body" tag to give it the color you want.

bigANARCHY
  • 11
  • 2
0

This is another solution, wrap your content into another div with a width of 1000px, then set margin:0 auto; which means center it on the page and it'll be fluid to any screen resolution

Here is the CSS with new style ID content-wrapper and the HTML

#MainWrapper {
    height:3000px;
    min-width:1000px;
    background-color:#CCC;
}
#TopWrapper {
    background-image:url(images/topwrapper.png);
    background-repeat:no-repeat;
    background-position: center bottom;
    min-width:100%;
    height:77px;
    margin: 0;
}
#Content {
    height:3000px;
    width:630px;
    background-color: #0F0;
    float:left;
    display:inline;
}
#Sidebar {
    height:3000px;
    width:350px;
    background-color: #00F;
    margin-left:20px;
    float:left;
    display:inline;
}
#content-wrapper {
    margin:0 auto;
    width:1000px;
}

<div id="TopWrapper"></div>
<div id="MainWrapper">
  <div id="content-wrapper">
    <div id="Content"></div>
    <div id="Sidebar"></div>
  </div>
</div>
Anagio
  • 3,005
  • 9
  • 44
  • 81