輪播是一個(gè)一個(gè)幻燈片組件,用來循環(huán)顯示圖片元素,或者滾動(dòng)的文字。
以下實(shí)例創(chuàng)建了一個(gè)簡單的圖片輪播效果 :
實(shí)例:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap4 實(shí)例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js" rel="external nofollow" rel="external nofollow" ></script>
<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js" rel="external nofollow" rel="external nofollow" ></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" ></script>
<style>
/* Make the image fully responsive */
.carousel-inner img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- 指示符 -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- 輪播圖片 -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201803/24575.png">
</div>
<div class="carousel-item">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201801/31740.png">
</div>
<div class="carousel-item">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201804/30601.png">
</div>
</div>
<!-- 左右切換按鈕 -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</body>
</html>
在每個(gè) <div class="carousel-item"> 內(nèi)添加 <div class="carousel-caption"> 來設(shè)置輪播圖片的描述文本::
實(shí)例:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap4 實(shí)例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js" rel="external nofollow" rel="external nofollow" ></script>
<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js" rel="external nofollow" rel="external nofollow" ></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" ></script>
<style>
/* Make the image fully responsive */
.carousel-inner img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- 指示符 -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- 輪播圖片 -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201803/24575.png">
<div class="carousel-caption">
<h3>第一張圖片描述標(biāo)題</h3>
<p>描述文字!</p>
</div>
</div>
<div class="carousel-item">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201702/43125.png">
<div class="carousel-caption">
<h3>第二張圖片描述標(biāo)題</h3>
<p>描述文字!</p>
</div>
</div>
<div class="carousel-item">
<img src="https://atts.w3cschool.cn/attachments/knowledge/201804/30601.png">
<div class="carousel-caption">
<h3>第三張圖片描述標(biāo)題</h3>
<p>描述文字!</p>
</div>
</div>
</div>
<!-- 左右切換按鈕 -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</body>
</html>
更多建議: