- Bootstrap 教程
- Bootstrap - 首頁
- Bootstrap - 概述
- Bootstrap - 環境設定
- Bootstrap - RTL(從右到左)
- Bootstrap - CSS 變數
- Bootstrap - 顏色模式
- Bootstrap 佈局
- Bootstrap - 斷點
- Bootstrap - 容器
- Bootstrap - 網格系統
- Bootstrap - 列
- Bootstrap - 間距
- Bootstrap - 實用工具類
- Bootstrap - CSS 網格
- Bootstrap 元件
- Bootstrap - 手風琴
- Bootstrap - 警報
- Bootstrap - 徽章
- Bootstrap - 麵包屑
- Bootstrap - 按鈕
- Bootstrap - 按鈕組
- Bootstrap - 卡片
- Bootstrap - 走馬燈
- Bootstrap - 關閉按鈕
- Bootstrap - 摺疊
- Bootstrap - 下拉選單
- Bootstrap - 列表組
- Bootstrap - 模態框
- Bootstrap - 導航欄
- Bootstrap - 導航和選項卡
- Bootstrap - 側邊欄
- Bootstrap - 分頁
- Bootstrap - 佔位符
- Bootstrap - 氣泡提示
- Bootstrap - 進度
- Bootstrap - 滾動偵聽
- Bootstrap - 載入動畫
- Bootstrap - 提示框
- Bootstrap - 工具提示
- Bootstrap 表單
- Bootstrap - 表單
- Bootstrap - 表單控制元件
- Bootstrap - 選擇框
- Bootstrap - 複選框和單選按鈕
- Bootstrap - 範圍滑塊
- Bootstrap - 輸入組
- Bootstrap - 浮動標籤
- Bootstrap - 佈局
- Bootstrap - 驗證
- Bootstrap 輔助類
- Bootstrap - 清除浮動
- Bootstrap - 顏色和背景
- Bootstrap - 彩色連結
- Bootstrap - 聚焦環
- Bootstrap - 圖示連結
- Bootstrap - 定位
- Bootstrap - 比例
- Bootstrap - 堆疊
- Bootstrap - 拉伸連結
- Bootstrap - 文字截斷
- Bootstrap - 垂直線
- Bootstrap - 視覺隱藏
- Bootstrap 實用工具類
- Bootstrap - 背景
- Bootstrap - 邊框
- Bootstrap - 顏色
- Bootstrap - 顯示
- Bootstrap - 彈性盒子
- Bootstrap - 浮動
- Bootstrap - 互動
- Bootstrap - 連結
- Bootstrap - 物件適配
- Bootstrap - 不透明度
- Bootstrap - 溢位
- Bootstrap - 定位
- Bootstrap - 陰影
- Bootstrap - 尺寸
- Bootstrap - 間距
- Bootstrap - 文字
- Bootstrap - 垂直對齊
- Bootstrap - 可見性
- Bootstrap 演示
- Bootstrap - 網格演示
- Bootstrap - 按鈕演示
- Bootstrap - 導航演示
- Bootstrap - 部落格演示
- Bootstrap - 滑塊演示
- Bootstrap - 走馬燈演示
- Bootstrap - 頁首演示
- Bootstrap - 頁尾演示
- Bootstrap - 英雄圖演示
- Bootstrap - 特色演示
- Bootstrap - 側邊欄演示
- Bootstrap - 下拉選單演示
- Bootstrap - 列表組演示
- Bootstrap - 模態框演示
- Bootstrap - 徽章演示
- Bootstrap - 麵包屑演示
- Bootstrap - 特大標題演示
- Bootstrap - 粘性頁尾演示
- Bootstrap - 相簿演示
- Bootstrap - 登入演示
- Bootstrap - 定價演示
- Bootstrap - 結賬演示
- Bootstrap - 產品演示
- Bootstrap - 封面演示
- Bootstrap - 儀表盤演示
- Bootstrap - 粘性頁尾導航欄演示
- Bootstrap - 砌體佈局演示
- Bootstrap - 模板啟動程式演示
- Bootstrap - RTL 相簿演示
- Bootstrap - RTL 結賬演示
- Bootstrap - RTL 走馬燈演示
- Bootstrap - RTL 部落格演示
- Bootstrap - RTL 儀表盤演示
- Bootstrap 有用資源
- Bootstrap - 問答
- Bootstrap - 快速指南
- Bootstrap - 有用資源
- Bootstrap - 討論
Bootstrap - 進度條
本章討論 Bootstrap 進度條。Bootstrap 中的進度條是顯示任務或程序進度或完成狀態的 UI 元件。它們通常用於直觀地指示操作的進度,例如檔案上傳、表單提交或資料載入。
Bootstrap 提供了一組內建類,用於建立具有不同樣式、大小和動畫的進度條。Bootstrap 還提供其他類和選項,用於自定義進度條的外觀和行為,例如設定不同的顏色、新增標籤、使用條紋或動畫進度條以及將多個進度條堆疊在一起。
使用 `.progress` 作為包裝器來顯示進度條的最大值。
使用內部 `.progress-bar` 來顯示目前的進度。
`.progress-bar` 需要內聯樣式、實用工具類或自定義 CSS 來設定其寬度。
`.progress-bar` 還需要一些 `role` 和 `aria` 屬性以使其可訪問。
`.progress-stacked` 可用於建立多個/堆疊的進度條。
基本進度條
這是一個基本的 Bootstrap 進度條示例
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar</h4><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</body>
</html>
條形大小
寬度
Bootstrap 提供了完整的設定寬度的實用工具列表。讓我們看一個例子
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar</h4><br><br>
<div class="progress">
<div class="progress-bar w-25" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</body>
</html>
高度
預設情況下,進度條的高度為 `1rem`,但可以使用 CSS `height` 屬性更改它。您必須為進度容器和進度條設定相同的高度。
高度值只能在 `.progress` 上設定,因此一旦在 `.progress` 容器中更改了高度值,內部 `.progress-bar` 就會自動調整大小。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar Height</h4><br>
<div class="progress" style="height: 20px;">
<div class="progress-bar" role="progressbar" style="width: 25%;height: 20px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<br>
<div class="progress" style="height: 30px;">
<div class="progress-bar" role="progressbar" style="width: 25%;height: 30px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</body>
</html>
標籤
可以透過將文字放在 `.progress-bar` 內來向進度條新增標籤。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar Label</h4><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 50%;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">50%</div>
</div>
</body>
</html>
標籤溢位可見/隱藏
為了避免內容超出條形,使用 `overflow: hidden` 來控制 `.progress-bar` 內的內容。
使用溢位實用工具中的 `overflow: visible` 使內容被限制並變得可讀。當進度條比標籤短時,這很有用。
定義明確的文字顏色以使文字可讀。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar Long Label</h4><br>
<div class="progress" role="progressbar" aria-label="Example of label" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar overflow-visible text-dark" style="width: 20%">Overflow visible on progress bar, but the label is too long, but the label is too long,but the label is too long,but the label is too long,but the label is too long,but the label is too long,but the label is too long</div>
</div>
<br>
<div class="progress" role="progressbar" aria-label="Example of label" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar overflow-hidden text-dark" style="width: 20%">Overflow hidden on progress bar, but the label is too long, but the label is too long,but the label is too long,;/div>
</div>
</body>
</html>
背景
可以使用背景實用工具類更改單個進度條的外觀。
進度條預設為藍色(主要)。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar Background</h4><br>
<!-- Blue -->
<div class="progress">
<div class="progress-bar" style="width:10%"></div>
</div><br>
<!-- Green -->
<div class="progress">
<div class="progress-bar bg-success" style="width:20%"></div>
</div><br>
<!-- Turquoise -->
<div class="progress">
<div class="progress-bar bg-info" style="width:30%"></div>
</div><br>
<!-- Orange -->
<div class="progress">
<div class="progress-bar bg-warning" style="width:40%"></div>
</div><br>
<!-- Red -->
<div class="progress">
<div class="progress-bar bg-danger" style="width:50%"></div>
</div><br>
<!-- White -->
<div class="progress border">
<div class="progress-bar bg-white" style="width:60%"></div>
</div><br>
<!-- Grey -->
<div class="progress">
<div class="progress-bar bg-secondary" style="width:70%"></div>
</div><br>
<!-- Light Grey -->
<div class="progress border">
<div class="progress-bar bg-light" style="width:80%"></div>
</div><br>
<!-- Dark Grey -->
<div class="progress">
<div class="progress-bar bg-dark" style="width:90%"></div>
</div>
</body>
</html>
輔助功能提示: 使用顏色來表示進度條僅提供視覺指示,這對螢幕閱讀器等輔助技術的使用者沒有幫助。確保含義本身就清晰明瞭。
使用其他方法使用 `.visually-hidden 類` 來增加內容的清晰度。
為了使標籤在彩色背景上可讀,請選擇合適的文字顏色。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar - Text Color</h4>
<br>
</div><div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-success" style="width: 25%">Default text color</div>
</div><br>
<div class="progress" role="progressbar" aria-label="Info example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-info text-dark" style="width: 50%">Dark text on Info</div>
</div><br>
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-warning text-dark" style="width: 75%">Dark text on warning</div>
</div><br>
<div class="progress" role="progressbar" aria-label="Danger example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar bg-danger" style="width: 100%">Light text on danger</div>
</div>
</body>
</html>
您還可以使用新的組合輔助類來設定文字和背景顏色,即顏色和背景。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar - Text & Background Color</h4>
<br>
<div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar text-bg-success" style="width: 75%">Text and Background Color</div>
</div>
</body>
</html>
多個條形
進度條可以有多個堆疊的進度條。使用 Bootstrap 類 `.progress-stacked` 來建立多個條形。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Progress Bar - Multiple</h4>
<br>
<div class="progress-stacked">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-danger" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</body>
</html>
條紋進度條
可以使用 `.progress-bar-striped` 類新增到任何 `.progress-bar` 中來為進度條新增條紋。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Striped Progress Bar</h4><br>
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div><br>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</body>
</html>
動畫條紋
可以向進度條新增動畫,條紋透過 CSS3 動畫從右到左移動。將 `.progress-bar-animated` 類新增到 `.progress-bar`。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Progress</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<h4>Animated Progress Bar</h4><br>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
</div>
</body>
</html>