Let's say I have a div containing a child div. The div container is set to margin: 0 auto, so when the width increases, the div expands on both sides. If the div inside this container was also set to margin: 0 auto, is there a way for this div to expand beyond its container div and go right and left the same way?
The following example shows that when .background is expanded beyond the width of the container, its size increases only on the right side, and not on both sides.
css and html:
.container { width: 600px; background-color: lightgreen; margin: 0 auto; } .background { width: 300px; margin: 0 auto; background-color: blue; } .content { width: 200px; background-color: lightblue; margin: 0 auto; }
<div class = "container"> <div class = "background"> <div class = "content"> content </div> </div> </div>
http://jsfiddle.net/DpYGm/2/
All this is an attempt to get a graphic background image of the banner to cover the width of the body of the page, but the content on the inside of the page will remain the same.
source share