How to create a 100% screen width div inside a container in bootstrap?

HtmlCssTwitter BootstrapTwitter Bootstrap-3

Html Problem Overview


Let's say i have the following markup:

<div class="container">
    <div class="row">
        <div class="col-md-12">
            ...
            <div class="full-width-div">
            </div>
        </div>
    </div>
</div>

Now how to make .full-width-div stretch to the full width of the screen? Because currently it's limited inside the container.

Html Solutions


Solution 1 - Html

2019's answer as this is still actively seen today

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.

original hack from 2015 that still works in some situations

You should pull that div outside of the container. You're asking a div to stretch wider than its parent, which is generally not recommended practice.

If you cannot pull it out of the div for some reason, you should change the position style with this css:

.full-width-div {
    position: absolute;
    width: 100%;
    left: 0;
}

Instead of absolute, you could also use fixed, but then it will not move as you scroll.

Solution 2 - Html

You should use container-fluid, not container. See example: http://www.bootply.com/onAFpJcslS

Solution 3 - Html

The reason why your full-width-div doesn't stretch 100% to your screen it's because of its parent "container" which occupies only about 80% of the screen.

If you want to make it stretch 100% to the screen either you make the "full-width-div" position fixed or use the "container-fluid" class instead of "container".

see Bootstrap 3 docs: http://getbootstrap.com/css/#grid

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIrshuView Question on Stackoverflow
Solution 1 - HtmlCodyView Answer on Stackoverflow
Solution 2 - HtmlShawn TaylorView Answer on Stackoverflow
Solution 3 - HtmlRene PadilloView Answer on Stackoverflow