html nav nav-tabs左右切换的案例
时间: 2023-08-22 20:35:49 浏览: 142
html 实现tab切换的示例代码
以下是一个简单的HTML nav nav-tabs左右切换的案例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Nav Tabs</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Nav Tabs</h2>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#tab1">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab2">Tab 2</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab3">Tab 3</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab4">Tab 4</a>
</li>
</ul>
<div class="tab-content">
<div id="tab1" class="tab-pane fade show active">
<h3>Tab 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt nisi ac tellus maximus dictum. Sed aliquam libero vel tellus tristique laoreet. Donec id enim ac arcu bibendum vestibulum. Proin nec purus quis elit interdum finibus sit amet vel ex. Nulla facilisi. Sed nec sapien euismod, aliquam ante eu, imperdiet ante. Donec varius commodo sapien, eget ornare justo varius ac. Fusce egestas, nunc et imperdiet sodales, libero ipsum congue arcu, eu lacinia nulla ex eu elit. Praesent id neque ut nulla sagittis malesuada.</p>
</div>
<div id="tab2" class="tab-pane fade">
<h3>Tab 2</h3>
<p>Quisque tincidunt nisi ac tellus maximus dictum. Sed aliquam libero vel tellus tristique laoreet. Donec id enim ac arcu bibendum vestibulum. Proin nec purus quis elit interdum finibus sit amet vel ex. Nulla facilisi. Sed nec sapien euismod, aliquam ante eu, imperdiet ante. Donec varius commodo sapien, eget ornare justo varius ac. Fusce egestas, nunc et imperdiet sodales, libero ipsum congue arcu, eu lacinia nulla ex eu elit. Praesent id neque ut nulla sagittis malesuada.</p>
</div>
<div id="tab3" class="tab-pane fade">
<h3>Tab 3</h3>
<p>Sed aliquam libero vel tellus tristique laoreet. Donec id enim ac arcu bibendum vestibulum. Proin nec purus quis elit interdum finibus sit amet vel ex. Nulla facilisi. Sed nec sapien euismod, aliquam ante eu, imperdiet ante. Donec varius commodo sapien, eget ornare justo varius ac. Fusce egestas, nunc et imperdiet sodales, libero ipsum congue arcu, eu lacinia nulla ex eu elit. Praesent id neque ut nulla sagittis malesuada.</p>
</div>
<div id="tab4" class="tab-pane fade">
<h3>Tab 4</h3>
<p>Donec varius commodo sapien, eget ornare justo varius ac. Fusce egestas, nunc et imperdiet sodales, libero ipsum congue arcu, eu lacinia nulla ex eu elit. Praesent id neque ut nulla sagittis malesuada.</p>
</div>
</div>
</div>
</body>
</html>
```
注意,这个案例中使用了Bootstrap框架,所以需要引入Bootstrap的CSS和JavaScript文件。其中,`ul`元素的class为`nav nav-tabs`,`li`元素的class为`nav-item`,`a`元素的class为`nav-link`,`data-toggle`属性用于指定切换方式,`href`属性用于指定显示的内容。`div`元素的class为`tab-pane fade`,`id`属性需要与`a`元素的`href`属性对应。
阅读全文