我有一个Bootstrap轮播,在大屏幕上很好,但如果我减小屏幕尺寸,指示器会移动到图像下方,我会完全丢失标题文字。我肯定错过了什么。我希望图像上的指示符和文本与更大的屏幕一样。任何帮助表示赞赏...
<div class="container" id="index">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
<img src="img/lesson8-portfolioheroimage2.jpg" alt="...">
</div>
<div class="item">
<img src="img/portfolioheroimage.jpg" alt="...">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
</div>
<div class="item">
<img src="img/portfolioheroimage3.jpg" alt="...">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
答案 0 :(得分:0)
这是因为当您调整屏幕尺寸时,旋转木马中的图像会根据其宽高比调整大小。
删除.carousel-control { margin: 200px 0; }
,而.carousel-caption
代替padding-bottom
在bottom
中提供%
,并根据media queries
中的要求进行调整。< / p>
同时添加此css
.carousel-inner .item{
height: 100%;
}
.carousel-inner .item img {
width: 100%;
height: 100% !important;
object-fit: cover;
}
.carousel { margin-left: -15px; margin-right: -15px; }
.carousel-inner{ height: 400px; }
.carousel-caption { bottom: 30% !important; }
.carousel-inner .item{
height: 100%;
}
.carousel-inner .item img {
width: 100%;
height: 100% !important;
object-fit: cover;
}
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" id="index">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
<img src="http://placehold.it/200x200" alt="...">
</div>
<div class="item">
<img src="http://placehold.it/200x200" alt="...">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
</div>
<div class="item">
<img src="http://placehold.it/200x200" alt="...">
<div class="carousel-caption">
<h3>Example headline</h3>
<p>Example description</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</body>
</html>
&#13;
答案 1 :(得分:0)
您应该调整CSS文件中的图像高度,而不是更改轮播项目的大小。更改轮播项目将在屏幕宽度达到80%时显示标题,但小于该宽度时它将消失。
img {
max-height: 600px;
}