布局
在bootstrap中 响应式布局通过栅格系统达成的。
栅格系统主要构成元素 row 和 col (column)
有点像 Excel 单元格
一行最大允许12格的长度,超过12格长度就跳到下面一行
行定义用
<div class="row"></div>
列定义用
<div class="col-针对哪种设备-长度">asdsa</div>
设备:
图片来自
http://www.runoob.com/bootstrap/bootstrap-grid-system.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!--引入css,js文件-->
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css" >
<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6" style="background: #6666cc">a</div>
<div class="col-md-6" style="background: #66ccff">b</div>
</div>
</div>
</body>
</html>
给div添加多个class就能达到自适应的效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!--引入css,js文件-->
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css" >
<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-8" style="background: #6666cc">a</div>
<div class="col-md-6 col-xs-4" style="background: #66ccff">b</div>
</div>
</div>
</body>
</html>
调整浏览器大小看看
嵌套
div嵌套: 子div能达到的最大宽度为父div的宽度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!--引入css,js文件-->
<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css" >
<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-8" style="background: #6666cc">
<div class="col-md-6" style="background: #5e5e5e">c</div>
<div class="col-md-6" style="background: red">d</div>
</div>
<div class="col-md-6 col-xs-4" style="background: #66ccff">b</div>
</div>
</div>
</body>
</html>