I have a small problem. I am trying to align two divs side by side using CSS, however, I would like the center div to be positioned horizontally central in the page, I achieved this by using:
#page-wrap { margin 0 auto; }
That’s worked fine. The second div I would like positioned to the left side of the central page wrap but I can’t manage to do this using floats although I’m sure it is possible.
I would like to push the red div up alongside the white div.
Here is my current CSS concerning these two divs, sidebar being the red div and page-wrap being the white div:
#sidebar {
width: 200px;
height: 400px;
background: red;
float: left;
}
#page-wrap {
margin: 0 auto;
width: 600px;
background: #ffffff;
height: 400px;
}
If you wrapped your divs, like this:
You could use this styling:
This is a slightly different look though, so I’m not sure it’s what you’re after. This would center all
800pxas a unit, not the600pxcentered with the200pxon the left side. The basic approach is your sidebar floats left, but inside the main div, and the#page-wraphas the width of your sidebar as it’s left margin to move that far over.Update based on comments: For this off-centered look, you can do this:
With this styling: