本篇文章帶大家聊聊Bootstrap中的自適應(yīng)屏幕。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

Bootstrap是基于HTML.css.javaScript開發(fā)的簡潔,直觀,強(qiáng)悍的前端開發(fā)框架,使web開發(fā)跟家快捷能制作響應(yīng)式網(wǎng)頁.
bootstrap自適應(yīng):
Bootstrap根據(jù)屏幕大小吧設(shè)備分為超小屏幕,小屏幕,中等屏幕,大屏幕四種并把屏幕分為12列對應(yīng)屏幕寬度為:
超小屏幕(手機(jī)):0-768px 對應(yīng)設(shè)置 class=col-xs-number
小屏幕(平板):768-992px 對應(yīng)設(shè)置class=col-sm-number
中等屏幕(電腦):992-1200px 對應(yīng)設(shè)置 class=col-md-number
大屏幕(電腦):1200px-? 對應(yīng)設(shè)置 class=col-lg-number
在chrome瀏覽器,elements窗口中會發(fā)現(xiàn)當(dāng)屏幕寬度小于768時,只有com-xs-12生效。
自適應(yīng):網(wǎng)頁適應(yīng)不同設(shè)備 ,用bootstrap框架
原理:是媒體(設(shè)備/瀏覽器)查詢 @media only screen 查詢設(shè)備的寬度
底層是以@media only screen and (min-width:最小值) and (max-width:最大值)進(jìn)行呈現(xiàn):
例一對背景:
@media only screen and (min-width:0px) and (max-width:480px){
body{
background-color:red;
}
}
@media only screen and (min-width:481px) and (max-width:720px){
body{
background-color:green;
}
}
@media only screen and (min-width:721px){
body{
background-color:blue;
}
}例二對塊級元素p
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<style type="text/css">
div{
float:left;
}
/**小屏0px-768px*/
@media only screen and (min-width:0px) and (max-width:768px){
.sm-12{
width:100%;
}
}
/**大屏768*/
@media only screen and (min-width:768px){
.lg-6{
width:50%;
}
}
</style>
<!-- 兩個樣式不會同時生效 在小屏上sm-12生效, width是100%在大屏上lg-6生效,width50%
css中標(biāo)簽分塊級標(biāo)記和行級標(biāo)記,div是塊級元素 -->
<div class="sm-12 lg-6">div1</div>
<div class="sm-12 lg-6">div2</div>
</body>
</html>bootstarp對其進(jìn)行整合自適應(yīng)
步驟:
1、link標(biāo)簽引入bootstrap.css文件
2、在bootstrap中定義
1) 根元素必須是p class值必須等于container
2) 根元素必須包含行元素且行元素class值必須等于row
3) 行中包含列class的值必須為col-*-number
例如:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="bootstrap.css" rel="stylesheet" type="text/css"> </head> <body> <!-- 根元素必須是div class必須=container --> <div class="container"> <!-- 根元素必須包含行 class=row --> <div class="row"> <!-- 行中包含列 -- class=col-*-number--> <div class="col-xs-12 col-sm-6 col-md-4">div1</div> <div class="col-xs-12 col-sm-6 col-md-4">div2</div> <div class="col-xs-12 col-sm-6 col-md-4">div3</div> </div> <div class="row"></div> </div> </body> </html>






