使用bootstrap实现选项卡动态切换,要求如下。选项卡中包括首页,垃圾分类,关于作者; 9首页使用轮播图实现, 6点击垃圾分类,显示不垃圾分类的图片;关于作者,写上考生本人的“班级-学号-姓名”
时间: 2023-08-02 13:06:15 浏览: 243
基于bootstrap多功能选项卡
以下是一个使用 Bootstrap 实现选项卡动态切换的示例代码,满足您的要求:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选项卡动态切换示例</title>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">选项卡示例</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="#home" data-toggle="tab">首页</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#garbage" data-toggle="tab">垃圾分类</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#author" data-toggle="tab">关于作者</a>
</li>
</ul>
</div>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active" id="home">
<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 src="https://via.placeholder.com/800x400?text=Slide+1" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/800x400?text=Slide+2" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/800x400?text=Slide+3" class="d-block w-100" alt="...">
</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 class="tab-pane fade" id="garbage">
<img src="https://via.placeholder.com/800x400?text=Garbage" class="d-block w-100" alt="...">
</div>
<div class="tab-pane fade" id="author">
<p>班级:XXX</p>
<p>学号:XXX</p>
<p>姓名:XXX</p>
</div>
</div>
</body>
</html>
```
说明:
- 使用 Bootstrap 的导航菜单和选项卡组件实现选项卡效果。
- 首页使用了 Bootstrap 的轮播图组件,图片使用了 placeholder.com 提供的占位图。
- 垃圾分类选项卡中显示了一张图片。
- 关于作者选项卡中写上了考生本人的班级、学号和姓名,可以根据实际情况修改。
阅读全文