Different background color either side of page

Jesse picture Jesse · Jan 18, 2011 · Viewed 31k times · Source

I want to create a fixed-width layout where the background color on either side of the page is different, but with the background colours extending infinitely from either side of the page no matter how far you zoom out.

For example, I'm not looking to create a 9000x10 px image with the correct colours on either side and tiling it, as this would only work if you dont zoom out far enough to see the edge of the background image.

Is this possible?

Thanks!

Edit:

I should have specified, the background should cover the full height of the page, not just the height of the window/viewport.

Answer

Fred Nurk picture Fred Nurk · Jan 18, 2011

This seems to work:

<body>
<div id="bg-right"></div>
<!-- rest of page -->
</body>

body {
  background-color: purple;
}
#bg-right {
  background-color: yellow;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  right: 0;
  z-index: -1;
}