Bootstrap 提供了丰富的预定义样式和组件,可以通过简洁的 HTML 代码快速构建具有现代化外观和响应式设计的网页。以下是一个简单的示例展示如何使用 Bootstrap 的代码来创建一个基本的网页布局:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Example</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Bootstrap Example</h1>
<p>This is a simple example of using Bootstrap to create a webpage layout.</p>
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card Title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Learn more</a>
</div>
</div>
</div>
<div class="col-md-6">
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Placeholder Image">
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
在这个示例中,我们引入了 Bootstrap 的 CSS 和 JavaScript 文件,并使用了容器(container
)、行(row
)、列(col-md-6
)、卡片(card
)、按钮(btn
)等 Bootstrap 类来构建简单的网页布局。这样可以快速创建具有现代外观和响应式设计的网页。