使用bootstrap制作四个网页,各个网页有搜索框、侧边栏、网站介绍等,并且网页间可以互相连接
时间: 2024-01-14 19:02:44 浏览: 81
很好,这是一个很有挑战性的任务。下面是一个简单的例子,展示如何使用Bootstrap创建一个基本的网站,包括搜索框、侧边栏和网站介绍。你可以通过这个例子来学习如何使用Bootstrap制作网页,并且根据你的需求进行修改和扩展。
首先,我们需要创建一个基本的HTML文件,并且导入Bootstrap的CSS和JavaScript库。这里我们使用Bootstrap的CDN链接:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
</body>
</html>
```
接着,我们添加一个导航栏和一个搜索框。导航栏包括一个品牌logo和一些链接,搜索框位于导航栏的右侧。我们使用Bootstrap的`navbar`和`form-inline`类来实现这个效果。
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Contact</a>
</div>
<form class="form-inline ml-auto">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</body>
</html>
```
下一步,我们添加一个侧边栏和主要内容区域。侧边栏包括一些链接和一些简单的介绍,主要内容区域包括一些文章和图片。我们使用Bootstrap的`container-fluid`、`row`、`col-md-3`和`col-md-9`类来实现这个效果。
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#">About</a>
<a class="nav-item nav-link" href="#">Contact</a>
</div>
<form class="form-inline ml-auto">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<h3>Categories</h3>
<ul class="list-group">
<li class="list-group-item"><a href="#">Category 1</a></li>
<li class="list-group-item"><a href="#">Category 2</a></li>
<li class="list-group-item"><a href="#">Category 3</a></li>
</ul>
<h3>About</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ultricies eros id ligula eleifend, id posuere ex ornare.</p>
</div>
<div class="col-md-9">
<h2>Article 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ultricies eros id ligula eleifend, id posuere ex ornare. Nam vel elit eget enim bibendum aliquet. Sed vel semper nulla. Aenean sed urna eget massa feugiat finibus. Fusce varius, leo at elementum sagittis, sapien lectus blandit dolor, sit amet efficitur nibh velit id enim. Aliquam imperdiet ex in consectetur commodo. Maecenas euismod nunc a leo lacinia, sit amet sodales orci hendrerit. Sed suscipit felis ante, vel gravida risus dapibus a. Cras vitae magna metus. </p>
<img src="https://via.placeholder.com/800x400" class="img-fluid" alt="Responsive image">
<h2>Article 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ultricies eros id ligula eleifend, id posuere ex ornare. Nam vel elit eget enim bibendum aliquet. Sed vel semper nulla. Aenean sed urna eget massa feugiat finibus. Fusce varius, leo at elementum sagittis, sapien lectus blandit dolor, sit amet efficitur nibh velit id enim. Aliquam imperdiet ex in consectetur commodo. Maecenas euismod nunc a leo lacinia, sit amet sodales orci hendrerit. Sed suscipit felis ante, vel gravida risus dapibus a. Cras vitae magna metus. </p>
<img src="https://via.placeholder.com/800x400" class="img-fluid" alt="Responsive image">
<h2>Article 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ultricies eros id ligula eleifend, id posuere ex ornare. Nam vel elit eget enim bibendum aliquet. Sed vel semper nulla. Aenean sed urna eget massa feugiat finibus. Fusce varius, leo at elementum sagittis, sapien lectus blandit dolor, sit amet efficitur nibh velit id enim. Aliquam imperdiet ex in consectetur commodo. Maecenas euismod nunc a leo lacinia, sit amet sodales orci hendrerit. Sed suscipit felis ante, vel gravida risus dapibus a. Cras vitae magna metus. </p>
<img src="https://via.placeholder.com/800x400" class="img-fluid" alt="Responsive image">
</div>
</div>
</div>
</body>
</html>
```
最后,我们可以在不同的页面之间添加链接,以便用户可以轻松地浏览网站的不同部分。例如,我们可以在导航栏中添加一个链接到“About”页面,然后创建一个新的HTML文件来显示关于我们的信息。
这里是一个简单的例子,展示如何使用Bootstrap创建一个基本的网站。你可以根据你的需要进行修改和扩展,以创建一个更完整、更专业的网站。
阅读全文