简体   繁体   中英

Why min-height 100% is not working for my div?

Hi I have issue with my css code. I have to set min-height for my slider at minimum 100% height but this not working as I except. Why?

I need this becouse I have to put text inside my slider and if the height of screen is not enought I need area of slider automatic expand. So this means the whole page should work as slider at minimum 100% height of browser but if not enought place the slider should automatic expand.... I hope I explain it enought. Thx for help...

MyCodeSandbox: https://codesandbox.io/s/elastic-hooks-vvgf3?file=/index.html

My Code

 html, body{ height:100%; } .container-fluid{ min-height: 100%; } #carouselExampleIndicators, .carousel-item{ min-height: 100%; }
 <!doctype html> <html lang="sk"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://kit.fontawesome.com/18e42a7034.js" crossorigin="anonymous"></script> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/newStyle.css"> <title>SPŠIT | DOD</title></head> <body> <div class="container-fluid p-0"> <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li> <li data-target="#carouselExampleIndicators" data-slide-to="1"></li> <li data-target="#carouselExampleIndicators" data-slide-to="2"></li> </ol> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="assets/slider-electro.jpg" alt="First slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="assets/slider-engineer.jpg" alt="Second slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="assets/slider-ist.jpg" alt="Third slide"> </div> </div> <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="js/bootstrap.js"></script> </body> </html>

Use vh (relative to the height of the viewport) units instead of %, vh is relative to the screen height.

example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM