【发布时间】:2020-01-01 12:32:23
【问题描述】:
我正在尝试让 Carousel 占据导航页眉和页脚之间的空间,以便它占据整个屏幕,中间没有滚动条或空格并且是响应式的。
我认为问题出在 div class="carousel-item" 上,因为当我逐行注释代码时,这是唯一摆脱垂直滚动条的行。
通过降低高度来调整屏幕大小会产生一个我不想要的垂直滚动条。通过减小宽度来调整屏幕大小会在图像和页脚之间产生我不想要的间隙。
尝试了很多不同的方法..
HTML:
<!-- Page content -->
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="images/first.jpg" class="d-block w-100 fluid-img" alt="...">
</div>
<div class="carousel-item">
<img src="images/first.jpg" class="d-block w-100 fluid-img" alt="...">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Bootstrap4 CSS:
.carousel {
position: relative;
}
.carousel-inner {
position: relative;
width: 100%;
overflow: hidden;
}
.carousel-item {
position: relative;
display: none;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
transition: -webkit-transform 0.6s ease;
transition: transform 0.6s ease;
transition: transform 0.6s ease, -webkit-transform 0.6s ease;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-perspective: 1000px;
perspective: 1000px;
}
我自己的 CSS:
/*background image*/
body{
background-image:url("../images/grass3.png");
width:100%;
height:100vh !important; //max size
}
.carousel-inner{
max-height:100% !important;
min-height:100% !important;
}
【问题讨论】:
-
是否允许固定页眉和页脚的位置?
-
CarouselHeight = totalHeight - (headerHeight + footerHeight) 这可能有助于避免滚动
-
嗨,Krishna,我在标题中添加了固定顶部而不是粘性顶部。页脚是固定底部。即使使用垂直滚动条,它看起来还可以,但仍然没有响应。
标签: javascript html css carousel