Twitter Bootstrap: div in container with 100% height

前端 未结 4 1811
旧巷少年郎
旧巷少年郎 2020-11-30 18:37

Using twitter bootstrap (2), I have a simple page with a nav bar, and inside the container I want to add a div with 100% height (to the bottom of the screen). M

相关标签:
4条回答
  • 2020-11-30 18:52

    It is very simple. You can use

    .fill .map 
    {
      min-height: 100vh;
    }
    

    You can change height according to your requirement.

    0 讨论(0)
  • 2020-11-30 18:57

    Set the class .fill to height: 100%

    .fill { 
        min-height: 100%;
        height: 100%;
    }
    

    JSFiddle

    (I put a red background for #map so you can see it takes up 100% height)

    0 讨论(0)
  • 2020-11-30 19:00

    you need to add padding-top to "fill" element, plus add box-sizing:border-box - sample here bootply

    0 讨论(0)
  • 2020-11-30 19:16

    Update 2019

    In Bootstrap 4, flexbox can be used to get a full height layout that fills the remaining space.

    First of all, the container (parent) needs to be full height:

    Option 1_ Add a class for min-height: 100%;. Remember that min-height will only work if the parent has a defined height:

    html, body {
      height: 100%;
    }
    
    .min-100 {
        min-height: 100%;
    }
    

    https://codeply.com/go/dTaVyMah1U

    Option 2_ Use vh units:

    .vh-100 {
        min-height: 100vh;
    }
    

    https://codeply.com/go/kMahVdZyGj

    Also of Bootstrap 4.1, the vh-100 and min-vh-100 classes are included in Bootstrap so there is no need to for the extra CSS

    Then, use flexbox direction column d-flex flex-column on the container, and flex-grow-1 on any child divs (ie: row) that you want to fill the remaining height.

    Also see:
    Bootstrap 4 Navbar and content fill height flexbox
    Bootstrap - Fill fluid container between header and footer
    How to make the row stretch remaining height

    0 讨论(0)
提交回复
热议问题