📅  最后修改于: 2023-12-03 15:29:38.464000             🧑  作者: Mango
Bootstrap是一套开源前端框架,由Twitter的前端工程师Mark Otto和Jacob Thornton开发而成。Bootstrap提供了HTML、CSS和JavaScript等众多组件,可以帮助开发者轻松创建响应式的网站和应用程序。
Bootstrap有很多优点,其中一些重要的特点如下:
Bootstrap可以通过CDN或下载源代码的方式来使用。以下是通过CDN引入Bootstrap的例子:
<!DOCTYPE html>
<html>
<head>
<title>My Bootstrap Page</title>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>Hello, Bootstrap!</h1>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.bundle.min.js"></script>
</body>
</html>
在上面的例子中,我们首先通过CDN引入了Bootstrap的CSS样式文件,并在页面中创建了一个容器div。 然后,我们通过CDN引入了jQuery库和Bootstrap的JavaScript文件,以便实现一些组件和特效的功能。
以下是一些常见的Bootstrap组件示例:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
<form>
<div class="mb-3">
<label for="exampleInputUsername" class="form-label">Username</label>
<input type="text" class="form-control" id="exampleInputUsername">
</div>
<div class="mb-3">
<label for="exampleInputEmail" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail">
</div>
<div class="mb-3">
<label for="exampleInputPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword">
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
以上只是Bootstrap的一部分,还有更多组件和特效,具体可以参考官方文档。 总之,Bootstrap是一个十分优秀的前端框架,可以帮助开发者快速构建响应式的网站和应用程序,提高开发效率。