Escape the bounds of a div container

user725913 picture user725913 · Oct 14, 2011 · Viewed 31.9k times · Source

Alright, I understand that the purpose of a DIV is to contain its inner elements - I didn't want to upset anyone by saying otherwise. However, please consider the following scenario:

My web page (which only takes up a width of 70% of the entire page) is surrounded by a container (a div). However, under my navigation bar which is at the top of the page, I would like to create w banner that takes up 100% of the width of the entire page (which means it will have to extend outside the bounds of its container as the container is only taking up 70% of the page's width).

This is the basic idea that I am trying to accomplish: http://www.petersonassociates.biz/

Does anyone have any suggestions for how I could accomplish this? I'd appreciate any help.

Evan

Answer

Mark picture Mark · Oct 31, 2013

If you just want the background of the element to extend across the whole page this can also be achieved with negative margins.

In a nutshell (correction from comment):

.bleed {
padding-left: 3000px;
margin-left: -3000px;
padding-right: 3000px;
margin-right: -3000px;
}

That gives you horizontal scroll bars which you remove with:

body {overflow-x: hidden; }

There is a guide at http://www.sitepoint.com/css-extend-full-width-bars/. It might be more semantic to do this with psuedo elements: http://css-tricks.com/full-browser-width-bars/