bootstrap实现轮播图代码
时间: 2023-10-26 18:14:23 浏览: 124
以下是使用Bootstrap实现轮播图的代码示例:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap Carousel Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div id="myCarousel" class="carousel slide" 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>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="img1.jpg" alt="Image1">
<div class="carousel-caption">
<h3>Image1</h3>
<p>Description1</p>
</div>
</div>
<div class="item">
<img src="img2.jpg" alt="Image2">
<div class="carousel-caption">
<h3>Image2</h3>
<p>Description2</p>
</div>
</div>
<div class="item">
<img src="img3.jpg" alt="Image3">
<div class="carousel-caption">
<h3>Image3</h3>
<p>Description3</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>
```
其中,`<ol>` 标签用于设置轮播图的指示器,每个 `<li>` 标签对应一个轮播图图片。`<div class="carousel-inner">` 标签中的每个 `<div class="item">` 标签表示一个轮播项,`<img>` 标签用于设置图片,`<div class="carousel-caption">` 标签用于设置图片描述。最后,左右箭头控制使用 `<a class="left carousel-control" href="#myCarousel" data-slide="prev">` 和 `<a class="right carousel-control" href="#myCarousel" data-slide="next">` 标签实现。
阅读全文