Bootstrap
Bootstrap 是由 Twitter 公司开发维护的前端 UI 框架,它提供了大量编写好的 CSS 样式,允许开发者结合一定 HTML 结构及JavaScript,快速编写功能完善的网页及常见交互效果。
Bootstrap 框架下载
建议直接百度去官网下载 Bootstrap3 ,最新的Bootstrap4 开发都放弃维护和更新了不建议使用,官网地址 (Bootstrap中文网)。
在实际的开发中,我们都是按需导入,简单理解,需要用到啥,我们复制那个文件,没有必要都放入,提高性能。
响应式
响应式的开发离不开一个核心原理:媒体查询 (media) ,媒体查询能检测游览器视口的宽度然后可以类似伪类一样修改一些属性或者值,演示代码如下:
body {
background-color: gray;
}
/* 大于等于768px 为粉色 */
@media (min-width: 768px) {
body {
background-color: pink;
}
}
/* 大于等于992px 为蓝色 */
@media (min-width: 992px) {
body {
background-color: skyblue;
}
}
/* 大于等于992px 为绿色 */
@media (min-width: 1200px) {
body {
background-color: green;
}
}
媒体查询的具体事用场景1:
body {
max-width: 540px;
margin: 0 auto;
}
/* 大于等于540px 则不允许 html文字大小再改动,强制定为 54px*/
@media (min-width: 540px) {
html {
font-size: 54px !important;
}
}
媒体查询使用场景2 元素的显示和隐藏:
@media (max-width: 800px) {
.box div:nth-child(2) {
display: none;
}
.box div:last-child {
width: 350px;
}
}
媒体查询使用场景3:
响应式原理:通过@media媒体标签判断屏幕大小, 让盒子在不同宽度呈现不同的摆放顺序
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 1000px;
height: 150px;
/* background-color: pink; */
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.box div {
width: 25%;
background-color: skyblue;
height: 150px;
margin-bottom: 20px;
}
.box div:nth-child(even) {
background-color: pink;
}
@media (max-width: 992px) {
.box {
width: 768px;
}
.box div {
width: 50%;
}
}
@media (max-width: 768px) {
.box {
width: 100%;
}
.box div {
width: 100%;
}
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</body>
</html>
Bootstrap 的使用步骤
1、解压好了后打开并复制 css文件
引用到需要框架的 html 文件中
<link rel="stylesheet" href="./css/bootstrap.min.css">
2、如果需要 js ,则是一样,复制 js 文件并引入