我能够将自举4轮播和图像从平板电脑转移到桌面,但当手机处于纵向视图时,图像会拉伸到高。高度:100vh;在其他地方正确定位图像,但如何在纵向移动状态下覆盖它?
演示页面http://dninstalls.com/blankbootstrap/
CSS
.carousel {
width: 100% !important;
max-height: calc(100vh - 81px);
overflow: hidden;
}
.carousel,
.carousel-item img {
max-width: 100%;
height: auto;
width: 100%;
height: 100vh;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
@media (min-width: 576px) {
.container {
max-width: 540px;
min-height: auto;
max-height: auto;
}
}
@media (max-width: 575px) {
.container {
max-width: 100%;
min-height: auto;
max-height: auto;
}
}
}
HTML
<header id="carouselHeader" class="page-header">
<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>
<li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
</ol>
<!-- Carousel image 1 -->
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="assets/mbbj%20kids.png" alt="First slide">
</div>
<!-- Carousel image 2 -->
<div class="carousel-item">
<img class="d-block w-100" src="assets/mbjj%20kids2.jpeg" alt="Second slide">
</div>
<!-- Carousel image 3 -->
<div class="carousel-item">
<img class="d-block w-100" src="assets/mbjj%20adult.jpeg" alt="Third slide">
</div>
<!-- Carousel image 4 -->
<div class="carousel-item">
<img class="d-block w-100" src="assets/mbjj%20comp.png" 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>
</header>
答案 0 :(得分:0)
您需要删除vh属性并使用max-heignt,min-height属性和正确的媒体查询...
/* Portrait and Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
}
/* Portrait */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
您需要将max-height和min-height属性用于.carousel, .carousel-item img
此类。根据设备维度,应更改图像比例...请参阅以下链接,将在此处获取所有代码https://css-tricks.com/snippets/css/media-queries-for-standard-devices/