Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap div stretch to bottom of page

I have the default bootstrap template setup, and my problem is that there is white space between a div and the footer. The white space is caused by not having enough content to fill up the entire page, so the body shows in between the footer and the content div. Is there a way to stretch a bootstrap div to the bottom of the page while also making the footer to stay at the very bottom? Possibly with flex box?

Here is the code I'm working with: (trying to stretch the "wrapper" div to the footer)

HTML

<body ng-app="firstApp">
    <div ng-view="" class="everything">

        <div class="wrapper">
            <div class="mid">
                <div class="row">
                    <div class="col-sm-12">
                        <p>This is in a div that should fill the screen</p>
                    </div>
                </div>
            </div>
           <div class="push"></div>
        </div>

       <footer class="footer">
           <div class="container">
               <p>Hello I'm the footer</p>
           </div>
       </footer>
</div> <!--closes the "everything" class -->

CSS

    html {
        height: 100%;
    }

 body {
    height: 100% !important;
    font-family: 'Roboto', sans-serif;
    color: black;
    background: green;
 }

.footer {
    text-align: center;
    padding: 30px 0;
    height: 4em;
    background-color: #7ccbc8;
    width: 100%;
}

I've read many stackoverflow posts on this topic, butI'm still pretty confused about the best practice for this.

like image 608
Troy Griffiths Avatar asked May 27 '15 23:05

Troy Griffiths


People also ask

How do I extend a div to the bottom of the page?

If you need to make a <div> element extend to the bottom and fill the page, try the following. Use viewport units and set the height and width of the <body> element to “100vh” and “100vw” respectively. Both the margin and padding of the <html> and <body> elements must be set to 0.

How do I get the footer to stay at the bottom of bootstrap?

In order for this element position at the bottom of the page, you have to add fixed-bottom to the class footer .

How do I center a div in bootstrap?

Add . align-items-center to the parent element to center its content vertically. Add . justify-content-center to the parent element to center its content horizontally.

How do I right align bootstrap?

Using .align-self-end is used to align a single item in a Flexbox to the right.


1 Answers

Troy, here it is so you can do that.

Set both the html and the body to height:100vh; and also set your div to the same height:100vh;

You can see this in this post that had the same issue.

like image 152
AngularJR Avatar answered Oct 11 '22 06:10

AngularJR