Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break element out of container

Tags:

html

css

position

I have all my content wrapped in a container element with a fixed width.

But I have a <div> that I want to "break out" of that container to span the full width of the page.

http://dabblet.com/gist/3207168

enter image description here

As you can see in that example, I've got the <div> to break out, but since it's positioned absolutely, it doesn't affect the flow of the page...which is what I'd like it to do.

I want it to act like it's in the flow of the page, but expand the full width of the window.

like image 442
Shpigford Avatar asked Jul 30 '12 14:07

Shpigford


People also ask

How do you break out of a container in CSS?

The . A simple utility class, . full-width , will break the image out of it's parent container using some negative margins, relative positioning, and the viewport width ( vw ) unit of measure. Add it to your image, and the CSS handles the rest.

How do you make a div inside a container full width?

You should likely change the . container to . container-fluid, which will cause your container to stretch the entire screen. This will allow any div's inside of it to naturally stretch as wide as they need.

How do I make an image out of a div?

Give your image a margin: 10px. That will do the trick.


1 Answers

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.

like image 141
fboes Avatar answered Oct 07 '22 17:10

fboes