这个问题与以下内容完全相同:
我的页面上有一个旋转木马。我希望它的宽度为100%。即使在一个类中将其宽度定义为100%之后,对Carousel也没有影响。如何使其宽度100%并具有响应性?
以下是我用过的最大宽度为100%的课程: -
.cwidth{
min-width: 100%;
}
以下是我的Carousel代码: -
<div class="container">
<h2>Carousel Example</h2>
<div id="myCarousel" class="carousel slide cwidth" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
<li data-target="#myCarousel" data-slide-to="4"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="Images/LIB01.png" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="Images/LIB02.png" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="Images/LIB03.png" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="Images/LIB04.png" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="Images/LIB05.png" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
检查您添加的库,试试这个工作代码段,
jQuery('.carousel').carousel();
html,
body {
height: 100%;
}
.carousel,
.item,
.active {
height: 100%;
}
.carousel-inner {
height: 100%;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
background-size: cover;
}
.container {
width: 100% !important;
}
/* keep full widget on smaller screens */
@media (max-width: 767px) {
body {
padding-left: 0;
padding-right: 0;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<div class="container fill">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="active item">
<div class="fill" style="background-image:url('//placehold.it/1024x700/449955/FFF');">
<div class="container">
</div>
</div>
</div>
<div class="item">
<div class="fill" style="background-image:url('//placehold.it/1024x700');">
<div class="container">
</div>
</div>
</div>
<div class="item">
<div class="fill" style="background-image:url('//placehold.it/1024x700/CC1111/FFF');">
<div class="container">
</div>
</div>
</div>
</div>
<div class="pull-center">
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</div>
</div>
<!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.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron">
<h2>Carousel Example</h2>
<div id="myCarousel" class="carousel slide cwidth" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
<li data-target="#myCarousel" data-slide-to="4"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="//placehold.it/1024x700" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="//placehold.it/1024x700/449955/FFF" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="//placehold.it/1024x700/CC1111/FFF" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="//placehold.it/1024x700/000000/FFF" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
<div class="item">
<img src="//placehold.it/1024x700/CC3456/FFF" alt="LIB Image" style="width:100%;">
<div class="carousel-caption">
<h3>Some Text</h3>
<p>Some Text</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>