Bootstrap的使用一般有兩種方法:
- 引用在線的Bootstrap的樣式,
- 將Bootstrap下載到本地進行引用。
在線引用
基本模板如下:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap引入</title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" >
<!-- jQuery文件。務必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
優點:不用本地安裝Bootstrap,也不用考慮引用時的路徑問題
缺點:一旦在線樣式掛了,那么會影響整個頁面樣式的呈現
本地引用
- 將Bootstrap下載到本地。
- 直接訪問上述代碼中的3個網址來獲取代碼
- 去Bootstrap的官網 http://v3.bootcss.com/ 和JQuery
的官網 http://jquery.com/ 下載相應的文件
- 將需要的文件放在項目下,便于引用
bootstrap的目錄結構如下:
bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.css.map
│ ├── bootstrap.min.css
│ ├── bootstrap.min.css.map
│ ├── bootstrap-theme.css
│ ├── bootstrap-theme.css.map
│ ├── bootstrap-theme.min.css
│ └── bootstrap-theme.min.css.map
├── js/
│ ├── bootstrap.js
│ └── bootstrap.min.js
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
├── glyphicons-halflings-regular.woff
└── glyphicons-halflings-regular.woff2
最常用的是css/bootstrap.min.css
、js/bootstrap.min.js
jquery.min.js
可以在JQuery官網下載
最后,在相應文件中引入即可。
優點:確保網絡狀況不佳的情況下,頁面樣式依然可以正常顯示
缺點:需要提前安裝或下載,引用時要考慮路徑問題。