
- 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 - Jumbotron 演示
- 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 提供的 .stretched-link 類。
Bootstrap 中的 .stretched-link 類用於建立一個連結,該連結可以拉伸以填充整個父容器。
此類可用於任何可以包含連結的元素,例如 <div> 或 <a> 元素,以使整個元素可點選並充當連結。
任何具有 position:relative 幷包含具有 .stretched-link 類的連結的元素都是可點選的。
.stretched-link 類不能與大多數表格元素混合使用。
此類可以安全地新增到 卡片中,因為它們在 Bootstrap 中預設具有 position:relative。
不建議將拉伸連結與多個連結和點選目標混合使用。
帶有拉伸連結的卡片
這對於您希望使整個內容部分(例如卡片或列表項)可點選的情況非常有用。
讓我們看看在卡片中使用 .stretched-link 類的示例
示例
您可以使用 編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Card</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> <h4>Stretched link in a card</h4> <div class="card" style="width: 20rem;"> <img src="/bootstrap/images/tutimg.png" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Stretched link in a card</h5> <p class="card-text">Here is an example that shows the entire card as a link. This is because of the .stretched-link class of Bootstrap.</p> <a href="#" class="btn btn-primary stretched-link">View</a> </div> </div> </body> </html>
當自定義元件預設不具有 position: relative 時,需要新增 .position-relative 類以防止連結拉伸到父元素之外。
讓我們看看 .position-relative 類的用法示例
示例
您可以使用 編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stretched link</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> <h4>Custom component with stretched link</h4> <div class="d-flex position-relative"> <img src="/bootstrap/images/tutimg.png" class="flex-shrink-0 me-3" alt="..."> <div> <h5 class="mt-0">Custom component with stretched link using .position-relative</h5> <p>Here is an example showing the use of .position-relative class in a component that shows a stretched link usage.</p> <a href="#" class="stretched-link">View</a> </div> </div> </body> </html>
讓我們再看看一個 .position-relative 類的用法示例
示例
您可以使用 編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stretched link</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> <h4>Columns with stretched link</h4> <div class="row g-0 bg-body-secondary position-relative"> <div class="col-md-4 mb-md-0 p-md-4"> <img src="/bootstrap/images/tutimg.png" class="w-100" alt="..."> </div> <div class="col-md-4 p-4 ps-md-0"> <h5 class="mt-0">Columns with stretched link</h5> <p>Another example of strecthed link with .position-relative on this other custom component. You can use it here to give the component a bit of body and size.</p> <a href="#" class="stretched-link">View</a> </div> </div> </body> </html>
廣告