我正在学习,而tacher向我们询问了带有转盘的statis页面。所以我想使用boostrap。轮播有点有用,但我不知道如何使其居中,更重要的是,控件不起作用。
这是相关代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- CSS & BOOTSTRAP -->
<link rel="stylesheet" href="./css/bootstrap-4.5.2-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/main.css">
<title>Site Statique</title>
</head>
<body>
<div class="container">
<!-- ======================================================================== -->
<!-- CAROUSEL PLACEHOLDER -->
<!-- ======================================================================== -->
<div class="row">
<div class="col-md-12">
<div class="mx-auto">
<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="img-carousel d-block w-100"
src="./img/many_dices_1.png"
alt="First slide">
</div>
<div class="carousel-item">
<img class="img-carousel d-block w-100"
src="./img/dice_sheet.jpg"
alt="Second slide">
</div>
<div class="carousel-item">
<img class="img-carousel d-block w-100"
src="./img/D_20.webp"
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>
</div>
</div>
<!-- ======================================================================== -->
<!-- EO CAROUSSEL -->
<!-- ======================================================================== -->
<!-- Scripts tags -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="./css/bootstrap-4.5.2-dist/js/bootstrap.min.js"></script>
</body>
</html>
因此轮播可以正常工作,并且图像可以滑动,但是小图像不能居中,控件也不能工作。有什么想法吗? 预先感谢
更新: 现在控件可以工作了,但是我不知道如何使图像保持比例。这是我的CSS规则
.img-carousel{
width: auto;
height: 100%;
max-height: 500px;
}
答案 0 :(得分:1)
我修复了您的标记。您有些困惑:
<image>
中,有两个错误的class=""
,只需在班级后面加一个空格href="#"
,怎么办?工作示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- CSS & BOOTSTRAP -->
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link rel="stylesheet" href="./css/main.css">
<title>Site Statique</title>
</head>
<body>
<div class="container">
<!-- ======================================================================== -->
<!-- CAROUSEL PLACEHOLDER -->
<!-- ======================================================================== -->
<div class="row">
<div class="col-md-12">
<div class="mx-auto">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="" data-slide-to="0" class="active"></li>
<li data-target="" data-slide-to="1"></li>
<li data-target="" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="img-carousel d-block w-100"
src="https://via.placeholder.com/150"
alt="First slide">
</div>
<div class="carousel-item">
<img class="img-carousel d-block w-100"
src="https://via.placeholder.com/150"
alt="Second slide">
</div>
<div class="carousel-item">
<img class="img-carousel d-block w-100"
src="https://via.placeholder.com/150"
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>
</div>
</div>
<!-- ======================================================================== -->
<!-- EO CAROUSSEL -->
<!-- ======================================================================== -->
<!-- Scripts tags -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- JS, Popper.js, and jQuery -->
<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="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>