Bootstrap带给大家最大的便利莫过于它的栅格系统,栅格系统帮助我们快速构建响应式的网页布局,以适配各种尺寸的屏幕。Bootstrap虽然带给我们很多的便利,但是很多情况下我们只需要用到它提供的栅格系统,其他组件样式我们更倾向于自己实现,为了给网站瘦身,我们往往需要抽取其中的一部分,我们甚至可以把前缀‘col-’去掉以尽量瘦身(在不压缩的情况下该文件9K,删除了col-后为8k,压缩情况下有没有删除col-都为6k)。
Bootstrap媒体查询了3个尺寸,分别是大于768px,大于992px,大于1200px,即@media screen and (min-width: 768px)、@media screen and (min-width: 992px)、@media screen and (min-width: 1200px)。由于css文件是从上往下渲染网页的,所以渲染了前边的样式之后,若屏幕宽度小于768px,则下边的css样式不起作用,以达到移动设备优先的效果。那么设备宽度大于1200px的时候,3个媒体查询都成立,会执行哪一个呢?比如class=”col-lg-3 col-md-6”的时候。上边已经提到css是从上往下渲染网页的,当遇到相同样式属性时,编写在下边的样式属性会覆盖上边的样式属性。那么当设备宽度大于1200px时,由于col-md-6编写再col-lg-3之前,col-lg-3取缔了col-md-6的样式,所以样式为.col-lg-3{width:25%}。同理若设备宽度小于1200px大于992px那么由于@media screen and (min-width: 1200px)不成立,所以样式为.col-lg-6{width:50%}。如此类推。
值得注意的时为了兼容ie可以使用bootstrap提供的js,以下出自菜鸟教程
<!-- HTML5 Shiv 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
<!-- 注意: 如果通过 file:// 引入 Respond.js 文件,则该文件无法起效果 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
@charset "utf-8";
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, pre,dl, dt, dd, ul, ol, li, form, fieldset, lengend, button, input, textarea, th, td {
margin: 0;
padding: 0;
}
ul, ol {
list-style: none;
}
a {
text-decoration: none;
}
q:before, q:after {
content: '';
}
legend {
color: #000;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
button, textarea {
font-size: 100%;
border: 0;
}
fieldset, img {
border: 0;
}
a:hover {
-webkit-transition: all .5s;
transition: all .5s;
}
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
} /* common ========================================================================== */
.fl {
float: left;
*display: inline;
_display: inline;
}
.fr {
float: right;
*display: inline;
_display: inline;
}
.clearfix:after {
display: block;
clear: both;
content: '';
visibility: hidden;
height: 0;
}
.clearfix {
*zoom: 1;
} /* 栅格系统,移动设备优先 ========================================================================== */
.container {
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
}
.container-fluid {
margin-left: au