I have all my content wrapped in a container element with a fixed width.
But I have a
Building on top of voodoo417's solution with just adding a second wrapper and some slight modifications this can be done properly:
.outer-wrapper {
overflow:hidden;
min-width:300px;
}
.wrapper {
width:300px;
margin:0 auto;
background:yellow;
}
.break {
text-align:center;
font-weight:bold;
background:rgba(255,0,0, 0.5);
margin-left:-9999px;
margin-right:-9999px;
}
<div class="outer-wrapper">
<div class="wrapper">
<h1>Ipsum Dapibus Pellentesque Pharetra</h1>
<div class="break">This should be full width</div>
</div>
</div>
Here is the adapted jsfiddle:
http://jsfiddle.net/v53vv78d/2/
Another idea, which in modern browsers does stretch the .breakout
only to the width of the browser window:
body, html {
overflow-x: hidden;
margin: 0;
padding: 0;
}
div {
padding:0.5em;
}
.container {
width:300px;
background-color:rgba(255,255,0,0.5);
margin:auto;
}
.breakout {
margin:1em -100%; /* old browsers fallback */
margin:1em calc(50% - 50vw);
background-color:rgba(255,0,255,0.5)
}
<div class="container">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
<div class="breakout">
Break out of container
</div>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
</div>
Edit: The one and only Chris Coyier explains Full Width Containers in Limited Width Parents, which is somewhat similiar.
Maybe http://jsfiddle.net/sYv9g/1/?
.wrapper {
width:300px;
margin:0 auto;
background:yellow;
}
.break {
text-align:center;
font-weight:bold;
background:rgba(255,0,0, 0.5);
margin-left:-100%;
margin-right:-100%;
}
<div class="wrapper">
<h1>Ipsum Dapibus Pellentesque Pharetra</h1>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Etiam porta sem malesuada magna mollis euismod. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Sed posuere consectetur est at lobortis.</p>
<div class="break">This should be full width</div>
<p>Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Maecenas sed diam eget risus varius blandit sit amet non magna. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<div class="break">This should be full width</div>
<p>Nullam id dolor id nibh ultricies vehicula ut id elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla.</p>
<p>Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur blandit tempus porttitor.</p>
</div>
You could use negative margins to achieve this.
.wrapper {
width:300px;
margin:0 auto;
}
.break {
width: 600px;
margin-left:-150px;
}
The only problem is that you would need to specify the width of both elements.
EDIT: voodoo417's solution would be better...
I like this simple technique (thanks to Bust elements out of their containers with one line of CSS):
margin: 0 calc(50% - 50vw)
You can't actually make it break out of the wrapping div, but you can simulate this same effect by having the wrapping div be the full width of the page, and by wrapping the other elements on that page that are not supposed to be in your "break out" div inside a div that has a yellow background and 300px width.