views:

565

answers:

4

Hi, I have a centered div layout. The left side of the div in the background should be white and the right side should be green. Both should extend to infinity.

I think it should be quite simple but I just don't get it right now. Any easy solution? Thank you!

-----------------------------------------------------
(div 1)     __________________________ 
           |(div 2)         |         |
           |                |         |
           |                |         |
<- white   |     white      |  green  |   green  ->
           |                |         |
           |                |         |
           |________________|_________|

------------------------------------------------------
A: 

I'd put inside that div two other divs and give them the appropriate sizes and backgound colors

klez
The centered div2 is already inside that other div1. It is centered by using margin:auto. I don't think I can put two other divs inside there?
Christoph
sure you can. you will need to add the two more divs or deal with a repeating background image that does the color change for you.
YetAnotherDeveloper
+4  A: 

Add a background image with the two colors to the outer div and allow the browser to scale it (instead of tiling it).

Each color should fill exactly 50% of the width of the image to make sure the colors will never leak on either side.

Maybe even position the image absolutely behind the inner div.

For ideas how to stretch the image, see this question: http://stackoverflow.com/questions/1277330/css-background-repeat

Aaron Digulla
Thank you, works out pretty cool! Didn't even know you can stretch bg-images.
Christoph
A: 

You could have two divs on the outside, and then have one of your divs in each. Right-align and left-align respectively. Like so:

-----------------------------------------------------
(div)                       | (div)
           _________________|_________ 
           |(div)           |  (div)  |
           |                |         |
           |                |         |
<- white   |     white      |  green  |   green  ->
           |                |         |
           |                |         |
           |________________|_________|
                            |
------------------------------------------------------
James Wiseman
But this only works if the line between the two outer divs is exactly at 50% of the screen (which it is not in my layout)?
Christoph
A: 

how can i change the layout of the home page by including round corners in it

rohit