- 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 - Flex 佈局
- 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 - Jumbotrons 演示
- 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 5 中,焦點環是在元素獲得焦點時出現在其周圍的視覺指示器。焦點環是元素周圍出現的圓形輪廓,通常以對比色顯示,以指示該元素當前處於活動狀態並準備接收使用者的輸入。
Bootstrap 5 提供了一個內建的焦點環,預設情況下會應用於互動式元素,例如按鈕、連結和表單控制元件。
輔助類 .focus-ring 會移除 :focus 上的預設 outline,並用 box-shadow 替換它。
讓我們看一個展示 .focus-ring 用法的示例。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Helper</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.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid flex-grow-1">
<h4>Focus ring</h4>
<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-bg-light border rounded-2">
Example focus ring
</a>
<button class="button focus-ring py-1 px-2 text-bg-light border rounded-2">Click Me</button>
</div>
</body>
</html>
自定義焦點環
可以使用 CSS 變數、Sass 變數、實用工具類或自定義樣式來自定義焦點環。
CSS 變數
為了更改焦點環的預設外觀,請修改 CSS 變數 --bs-focus-ring-*。
讓我們看一個自定義 CSS 變數 --bs-focus-ring-* 的示例。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Helper</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.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid flex-grow-1">
<h4>Focus ring - Customize CSS variable</h4>
<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: rgba(var(--bs-danger-rgb), .25)">
Red focus ring
</a>
<div>
</body>
</html>
讓我們看一個自定義 CSS 變數 --bs-focus-ring-* 的示例,以使焦點環模糊。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Helper</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.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid flex-grow-1">
<h4>Focus ring - Customize CSS variable</h4>
<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-x: 20px; --bs-focus-ring-y: 20px; --bs-focus-ring-blur: 6px">
Blur focus ring
</a>
</div>
</body>
</html>
實用工具類
Bootstrap 提供了幾個實用工具類 .focus-ring-* 來修改預設設定。
例如,使用任何主題顏色修改焦點環的顏色。
讓我們看一個自定義實用工具類 .focus-ring-* 的示例。
示例
您可以使用“編輯和執行”選項編輯並嘗試執行此程式碼。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Helper</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.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid flex-grow-1">
<h4>Focus ring - Customize utilities</h4>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-success py-1 px-2">Success focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-info py-1 px-2">Info focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-warning py-1 px-2">Warning focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-danger py-1 px-2">Danger focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-secondary py-1 px-2">Secondary focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-primary py-1 px-2">Primary focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-dark py-1 px-2">Dark focus ring</a></p>
<p><a href="#" class="d-inline-flex focus-ring focus-ring-light py-1 px-2">Light focus ring</a></p>
</div>
</body>
</html>
廣告