If I have a 100% wide div element with 12 pixels of padding to the left and to the right, and I have an element inside the div that I want to span from one corner of the screen to another (bridging the 12 pixel gap), do I have any chance of “breaking out” of the surrounding div without using absolute positioning?
Using position:relative; left:-12px won’t work alone, because the div is 100% wide and I can’t specify “100% + 12px” to make the inner element touch the right hand corner.
A pure CSS solution:
Tested working in FF 3.5 and IE8. Other browsers not tested. With IE7 or before it might be weird.
I think the reason this works is because the browser adds the tag width with it’s white space (padding). In this case
margin-left: -12pxshifts the div to visually look like it’s ignoring the parent’spadding: 12px. At first I thoughtwidth: 100%; padding-right: 12px;alone would work, but it didn’t. I realized this is because the box model being used. It didn’t factor in the initial padding because it was collapsing with the parent’s padding (or so I am assuming).For reference here was my test page: