Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 691
Irshu Avatar asked Jun 04 '14 23:06

Irshu


People also ask

How do I create a 100% screen width div inside a container in Bootstrap?

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".

How do you make a div 100 width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.


2 Answers

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.

like image 63
Cody Avatar answered Sep 21 '22 21:09

Cody


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

like image 41
Shawn Taylor Avatar answered Sep 20 '22 21:09

Shawn Taylor