第一次接觸Bootstrap框架
關(guān)于Bootstrap,話(huà)不多說(shuō),直接進(jìn)入主題:
安裝
可以通過(guò)bootstrap官方網(wǎng)站下載安裝
可以通過(guò)Bower安裝(關(guān)于bower一種包管理器,本文不做詳解)
bower install bootstrap
可以通過(guò)npm安裝(關(guān)于npm可以閱讀)
npm install bootstrap
項(xiàng)目中引入Bootstrap
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>BootstrapDemo</title> <!--step1:設(shè)置viewport--> <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"> <!--step2:引入Bootstrap--> <link rel="stylesheet" href="css/bootstrap.css"> </head>
布局容器
.container 類(lèi)用于固定寬度并支持響應(yīng)式布局的容器
<div class="container"> </div>
.container-fluid 類(lèi)用于100%寬度,占據(jù)全部視口(viewport)的容器
<div class="container-fluid"> </div>
柵格系統(tǒng)
Bootstrap提供了一套響應(yīng)式的, 移動(dòng)優(yōu)先的流式柵格系統(tǒng), 隨著屏幕或視口(viewport)尺寸的不同, 系統(tǒng)會(huì)自動(dòng)的分成12份;
柵格系統(tǒng)是通過(guò)一系列的行(row)和列(column)的組合來(lái)創(chuàng)建頁(yè)面布局;
“行(row)”必須包含在.container或.container-fluid容器中,
柵格系統(tǒng)中的媒體查詢(xún)
柵格系統(tǒng)中的參數(shù)
案例代碼
<head> <meta charset="UTF-8"> <title>Title</title> <!--step1:設(shè)置viewport--> <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"> <!--step2:引入Bootstrap--> <link rel="stylesheet" href="css/bootstrap.css"> <style> .container .row div { background-color: grey; border:1px solid red; } </style> </head> <body> <div class="container"> <div class="row"> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">1</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">2</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">3</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">4</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">5</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">6</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">7</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">8</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">9</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">10</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">11</div> <div class="col-lg-1 col-md-2 col-sm-3 col-xs-6">12</div> </div> </div> </body>
頁(yè)面效果會(huì)隨著屏幕的大小col-lg-, col-md- ,col-sm-, col-xs- 顯示不同的效果
柵格系統(tǒng)中的列偏移(offsets)
col-lg-offset-
<head> <meta charset="UTF-8"> <title>Title</title> <!--step1:設(shè)置viewport--> <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"> <!--step2:引入Bootstrap--> <link rel="stylesheet" href="css/bootstrap.css"> <style> .container .row div { background-color: grey; border:1px solid red; } </style> </head> <body> <div class="container"> <div class="row"> <div class="col-lg-offset-11 col-lg-1">row - col -1</div> </div> </div> </body>
效果如下(偏移了11列)
柵格系統(tǒng)中的列嵌套
<div class="container"> <div class="row"> <div class="col-lg-4 col-md-2 col-sm-3 col-xs-6">1</div> <div class="col-lg-8 col-md-2 col-sm-3 col-xs-6">2 <div class="row"> <div class="col-lg-3 col-md-2 col-sm-3 col-xs-6">3</div> <div class="col-lg-3 col-md-2 col-sm-3 col-xs-6">4</div> <div class="col-lg-3 col-md-2 col-sm-3 col-xs-6">5</div> <div class="col-lg-3 col-md-2 col-sm-3 col-xs-6">6</div> </div> </div> </div> </div>
效果如下
流式布局容器
將最外面的布局元素.container 改為.container-fluid,就可以將固定的柵格布局轉(zhuǎn)換為100%寬度的布局
<div class="contaienr-fluid"> <div class="row"> </div> </div>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附兩個(gè)精彩的專(zhuān)題:Bootstrap學(xué)習(xí)教程 Bootstrap實(shí)戰(zhàn)教程
相關(guān)文章
Java?@Schema和@ApiModel等注解的聯(lián)系淺析
這篇文章主要給大家介紹了關(guān)于Java?@Schema和@ApiModel等注解的聯(lián)系的相關(guān)資料,我在看公司之前的文檔,發(fā)現(xiàn)了@schema注解,不太了解,所以查詢(xún)了一些資料,把我的見(jiàn)解記錄下,需要的朋友可以參考下2023-08-08javascript如何讀寫(xiě)本地sqlite數(shù)據(jù)庫(kù)
這篇文章主要介紹了javascript如何讀寫(xiě)本地sqlite數(shù)據(jù)庫(kù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02JavaScript實(shí)現(xiàn)留言板實(shí)戰(zhàn)案例
這篇文章主要給大家介紹了關(guān)于JavaScript實(shí)現(xiàn)留言板的相關(guān)資料,使用JavaScript來(lái)編寫(xiě)留言板功能相信大家都不陌生,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考下2023-07-07微信小程序?qū)崿F(xiàn)訂單倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)訂單倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06JS實(shí)現(xiàn)網(wǎng)頁(yè)頂部向下滑出的全國(guó)城市切換導(dǎo)航效果
這篇文章主要介紹了JS實(shí)現(xiàn)網(wǎng)頁(yè)頂部向下滑出的全國(guó)城市切換導(dǎo)航效果,涉及javascript鼠標(biāo)事件及頁(yè)面元素顯示的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08Firefox getBoxObjectFor getBoundingClientRect聯(lián)系
Firefox在含有flash的網(wǎng)頁(yè)上提示:不建議使用 getBoxObjectFor() 。 請(qǐng)使用 element.getBoundingClientRect()。2008-10-10