Bootstrap
1.简介
1.1 概述
Bootstrap是美国Twitter公司的设计师Mark otto和Jacob Thornton合作基于HTML、CSS、JavaScript 开发的简洁、直观、强悍的前端开发框架,使得 Web 开发更加快捷。Bootstrap提供了优雅的HTML和CSS规范,它即是由动态CSS语言Less写成。Bootstrap一经推出后颇受欢迎,一直是GitHub上的热门开源项目,包括NASA的MSNBC(微软全国广播公司)的Breaking News都使用了该项目。国内一些移动开发者较为熟悉的框架,如WeX5前端开源框架等,也是基于Bootstrap源码进行性能优化而来。
Bootstrap是一个前端开发框架
框架:一个半成品软件
好处:
1.2 快速入门
- 官网下载https://www.bootcss.com/
- 引入:在项目中将三个文件夹复制
- 创建html页面,引入必要的资源文件
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<Meta charset="utf-8">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<Meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个Meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap Hello World</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="js/jquery-3.6.0.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<h1>你好,世界!</h1>
</body>
</html>
这是模板文档,以后都在此基础上编写代码
2.响应式布局
同一套页面可以兼容不同分辨率的设备
实现:依赖于栅格系统:将一行平均分成12个格子,可以指定元素占几个格子
步骤:
1. 定义容器:相当于之前的table
1. container:两边留白
2. container-fluid:每一种都是100%宽度
2. 定义行:相当于之前的tr 样式:row
3. 定义元素:相当于之前的td。指定该元素在不同的设备上,所占的格子数
1. col-xs-:**超小屏幕** 手机 (<768px)
2. col-sm-:**小屏幕** 平板 (≥768px)
3. col-md-:**中等屏幕** 桌面显示器 (≥992px)
4. .col-lg-:**大屏幕** 大桌面显示器 (≥1200px)
注意:
- 如果一行格子数超出12个,超出部分自动换行
- 栅格类属性可以向上兼容。栅格类适用于与屏幕宽度大于或等于分界点大小的设备 , 并且针对小屏幕设备覆盖栅格类
- 如果真实设备宽度小于了设置栅格类属性的设备代码的最小值,会一个元素占满一整行
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<Meta charset="utf-8">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<Meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个Meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap栅格系统</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="js/jquery-3.6.0.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="js/bootstrap.min.js"></script>
<style>
.inner{
border: 1px solid;
}
</style>
</head>
<body>
<!--1.定义容器-->
<div class="container">
<!--2.定义行-->
<div class="row">
<!--3.定义元素
在大屏幕一行占12个格子
在pad上一行占6个格子
-->
<!--<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>
<div class="col-lg-1 col-sm-2 inner">栅格</div>-->
<!--<div class="col-lg-13 inner">栅格</div>-->
<!--<div class="col-xs-4 inner">栅格</div>
<div class="col-xs-4 inner">栅格</div>
<div class="col-xs-4 inner">栅格</div>-->
<div class="col-md-4 inner">栅格</div>
<div class="col-md-4 inner">栅格</div>
<div class="col-md-4 inner">栅格</div>
</div>
</div>
</body>
</html>
3.CSS样式
全局css样式:
-
按钮:class=“btn btn-default”
<!DOCTYPE html> <html lang="zh-CN"> <head> <Meta charset="utf-8"> <Meta http-equiv="X-UA-Compatible" content="IE=edge"> <Meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个Meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <title>Bootstrap CSS样式</title> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> <script src="js/jquery-3.6.0.min.js"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="js/bootstrap.min.js"></script> </head> <body> <a class="btn btn-default" href="#">Link</a> <button class="btn btn-default" type="submit">Button</button> <input class="btn btn-default" type="button" value="input"> <input class="btn btn-default" type="submit" value="submit"> <br> <button type="button" class="btn btn-default">(默认样式)Default</button> <button type="button" class="btn btn-primary">(首选项)Primary</button> <button type="button" class="btn btn-success">(成功)Success</button> <button type="button" class="btn btn-info">(一般信息)Info</button> <button type="button" class="btn btn-warning">(警告)Warning</button> <button type="button" class="btn btn-danger">(危险)Danger</button> <button type="button" class="btn btn-link">(链接)Link</button> <img src="../image/image07.jpg" class="img-responsive"> <img src="../image/image07.jpg" class="img-rounded"> <img src="../image/image07.jpg" class="img-circle"> <img src="../image/image07.jpg" class="img-thumbnail"> </body> </html>
-
表格:class=“table table-striped table-bordered table-hover”
<table class="table <!--table-striped--> table-bordered table-hover"> <tr> <th>no</th> <th>name</th> <th>age</th> </tr> <tr> <td>1</td> <td>jack</td> <td>20</td> </tr> <tr> <td>1</td> <td>jack</td> <td>20</td> </tr> <tr> <td>1</td> <td>jack</td> <td>20</td> </tr> </table>
-
表单:给表单项添加:class=“form-group”
<form class="form-horizontal"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">Email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">Password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="inputPassword3" placeholder="Password"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkBox"> <label> <input type="checkBox"> Remember me </label> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">Sign in</button> </div> </div> </form>
组件:
-
导航条
<nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Brand</a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> <li role="separator" class="divider"></li> <li><a href="#">One more separated link</a></li> </ul> </li> </ul> <form class="navbar-form navbar-left"> <div class="form-group"> <input type="text" class="form-control" placeholder="Search"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> <ul class="nav navbar-nav navbar-right"> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> </ul> </li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav>
-
分页条
<nav aria-label="Page navigation"> <ul class="pagination"> <li> <a href="#" aria-label="PrevIoUs"> <span aria-hidden="true">«</span> </a> </li> <li><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li> <a href="#" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav>
4.js插件
轮播图
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listBox">
<div class="item active">
<img src="../image/image07.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
<div class="item">
<img src="../image/image08.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
<div class="item">
<img src="../image/image09.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
...
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">PrevIoUs</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
案例:网站首页
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<Meta charset="utf-8">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<Meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个Meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>净心之旅</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="js/jquery-3.6.0.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="js/bootstrap.min.js"></script>
<style>
.header-img{
width: 100%;
height: 150px;
}
.margin-top{
margin-top: 10px;
}
.input-serch{
border: 2px solid #ffc600;
width: 300px;
height: 35px;
float: left;
margin-top: 40px;
padding-left: 10px;
}
.btn-serch{
border: 2px solid #ffc600;
width: 70px;
height: 35px;
background: #ffc600;
margin-top: 40px;
}
.tel-img{
margin-top: 40px;
margin-left: 200px;
}
.return-to{
margin-left: 40px;
width: 100px;
}
.title-choice{
border-bottom: 1px solid #ff8c00;
}
.choice-img{
width: 100%;
}
.comment-price{
color: red;
}
.footer-font{
color: #a9a9a9;
font-size: 3px;
font-family: 楷体;
margin-left: 40%;
}
</style>
</head>
<body>
<!--页眉部分-->
<header class="container-fluid">
<div class="row">
<div class="col-md-12">
<img src="../image/image01.jpg" class="header-img">
</div>
</div>
<div class="row">
<div class="col-md-4">
<img src="../image/image_log02.png" class="margin-top">
</div>
<div class="col-md-4">
<input type="text" class="input-serch" placeholder="请输入线路名称">
<input type="submit" class="btn-serch" value="搜索">
</div>
<div class="col-md-4">
<img src="../image/image_tel02.png" class="tel-img">
</div>
</div>
<div class="row margin-top">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">首页</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="return-to"><a href="#">门票</a></li>
<li class="return-to"><a href="#">酒店</a></li>
<li class="return-to"><a href="#">出境游</a></li>
<li class="return-to"><a href="#">国内游</a></li>
<li class="return-to"><a href="#">抱团游</a></li>
<li class="return-to"><a href="#">收藏排行榜</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
<div class="row">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listBox">
<div class="item active">
<img src="../image/image07.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
<div class="item">
<img src="../image/image08.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
<div class="item">
<img src="../image/image09.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">PrevIoUs</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</header>
<!--主体部分-->
<div class="container">
<div class="row margin-top">
<div class="col-md-12 title-choice">
<img src="../image/image_icon01.png">
精选推荐
</div>
</div>
<div class="row margin-top">
<div class="col-md-3 thumbnail">
<img src="../image/image03.jpg" class="choice-img ">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<span class="comment-price">¥ 899</span>
</div>
<div class="col-md-3 thumbnail">
<img src="../image/image04.jpg" class="choice-img ">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<span class="comment-price">¥ 899</span>
</div>
<div class="col-md-3 thumbnail">
<img src="../image/image05.jpg" class="choice-img ">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<span class="comment-price">¥ 899</span>
</div>
<div class="col-md-3 thumbnail">
<img src="../image/image06.jpg" class="choice-img ">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<span class="comment-price">¥ 899</span>
</div>
</div>
<div class="row margin-top">
<div class="col-md-12 title-choice">
<img src="../image/image_icon02.png">
国内游
</div>
</div>
<div class="row margin-top">
<div class="col-md-4 thumbnail">
<img src="../image/image10.jpg" class="choice-img">
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-4 thumbnail">
<img src="../image/image06.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<span class="comment-price">¥ 1199</span>
</div>
<div class="col-md-4 thumbnail">
<img src="../image/image04.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<font color="red">¥ 1099</font>
</div>
<div class="col-md-4 thumbnail">
<img src="../image/image05.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<font color="red">¥ 999</font>
</div>
</div>
<div class="row ">
<div class="col-md-4 thumbnail">
<img src="../image/image07.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<font color="red">¥ 1299</font>
</div>
<div class="col-md-4 thumbnail">
<img src="../image/image08.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<font color="red">¥ 899</font>
</div>
<div class="col-md-4 thumbnail">
<img src="../image/image09.jpg" class="choice-img">
<p>
上海飞三亚5天4晚自由行(春节销售+亲子+蜜月+自由行)
</p>
<font color="red">¥ 699</font>
</div>
</div>
</div>
</div>
</div>
<!--页脚部分-->
<footer class="container-fluid">
<div class="row margin-top">
<div class="col-md-12">
<img src="../image/image01.jpg" class="header-img">
</div>
</div>
<div class="row margin-top footer-font">
©2021 Baidu | 隐私政策 | 百度百科合作平台 | 京ICP证030173号
</div>
</footer>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。