bootstrap/
├── css/
│ ├── bootstrap.css /* 完整樣式 (含響應式),開發/除錯用 */
│ ├── bootstrap.min.css /* 生產環境:壓縮、無註解、最小體積 */
│ ├── bootstrap-theme.css /* 可選主題:立體/漸層/陰影風格 */
│ ├── bootstrap-theme.min.css
│ └── bootstrap.map / .min.map /* Source Map,支援 DevTools 對應源碼 */
├── js/
│ ├── bootstrap.js /* 完整 JS 插件 (含所有元件),開發/除錯用 */
│ ├── bootstrap.min.js /* 生產環境:壓縮版 */
│ └── npm.js /* npm 發布用進入點 (不含 jQuery) */
└── fonts/
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
├── glyphicons-halflings-regular.woff
└── glyphicons-halflings-regular.woff2
| 檔案 | 內容 | 使用時機 |
|---|---|---|
bootstrap.css | 所有元件樣式:網格、排版、表格、表單、按鈕、導航、元件、工具類、響應式斷點 | 開發環境、需閱讀/調試樣式 |
bootstrap.min.css | 同上,經壓縮 (移除空白、註解、縮短選擇器) | 生產環境,**必須使用** |
bootstrap-theme.css | 可選 3D/立體風格主題 (按鈕、面板、進度條等) | 需預設立體風格時引入,**在核心 CSS 之後** |
bootstrap.js | 所有 jQuery 插件:Modal、Dropdown、Tab、Tooltip、Popover、Carousel、Collapse、Affix、Scrollspy、Button、Transition | 開發環境 |
bootstrap.min.js | 同上,壓縮版 | 生產環境,**必須使用** |
| 字體檔案 | Glyphicons Halflings 圖標字體 (5 種格式跨瀏覽器) | 自動由 CSS @font-face 載入,**fonts/ 必須與 css/ 同層或正確配置路徑** |
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 1. 核心樣式 -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- 2. 可選主題 (若需) -->
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<!-- 3. 自定義樣式 (覆蓋/擴充 Bootstrap) -->
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<!-- 頁面內容 -->
<!-- 1. jQuery (Bootstrap JS 依賴,v3 需 1.9+ / v4+ 不需) -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- 2. Bootstrap JS -->
<script src="js/bootstrap.min.js"></script>
<!-- 3. 自定義腳本 -->
<script src="js/app.js"></script>
</body>
<head> 且無 defer → 執行時 DOM 未就緒,選擇器失效。Uncaught Error: Bootstrap's JavaScript requires jQuery。@font-face src 路徑相對 bootstrap.min.css 位置。v2.x 有獨立 bootstrap-responsive.css;**v3.x 起響應式樣式已整合進核心 CSS**,**不再需要**額外引入響應式檔案。若專案仍引用 v2.x 風格雙檔案,請確認版本並調整引入策略。
variables.less/_variables.scss 設計令牌,執行 grunt dist / npm run build 產出客製化版本。import 'bootstrap/scss/bootstrap.scss' 或按需 import 'bootstrap/js/dist/modal' 實現 Tree Shaking。理解 Bootstrap 目錄結構與引入順序,是避開「樣式不生效、JS 報錯、圖標缺失」等低級錯誤的前提,也是客製化主題、優化打包體積的基礎。