
- 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 - 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 中,縱橫比用於保持響應式元素(例如影像或影片)相對於其父容器的比例。它使用.ratio類以及表示所需縱橫比的修飾符類來指定。
要管理外部內容(如<iframe>、<embed>、<video>和<object>)的縱橫比,請使用ratio-*類。
比例輔助程式也可以用於標準 HTML 子元素,例如<div>或<img>。
樣式直接從父.ratio類應用到子元素。
縱橫比修飾符類中的*可以替換為:
ratio-21x9:建立一個具有 21:9 縱橫比的響應式元素
ratio-16x9:建立一個具有 16:9 縱橫比的響應式元素
ratio-4x3:建立一個具有 4:3 縱橫比的響應式元素
ratio-1x1:建立一個具有 1:1 縱橫比的響應式元素
這是一個關於如何在<iframe>元素中使用縱橫比的示例。這裡我們使用的是 16x9 縱橫比
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Ratio</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> <h2 class="text-success text-center"> Aspect Ratio 16x9 </h2> <hr> <div class="ratio ratio-16x9"> <iframe src="https://www.youtube.com/embed/4PWVFBiFVVU" title="YouTube video" allowfullscreen> </iframe> </div> </body> </html>
這是一個關於如何在<iframe>元素中使用縱橫比的示例。這裡我們使用的是 21x9 縱橫比
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Ratio</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> <h2 class="text-success text-center"> Aspect Ratio - 21x9 </h2> <hr> <div class="ratio ratio-21x9"> <iframe src="https://www.youtube.com/embed/4PWVFBiFVVU" title="YouTube video" allowfullscreen> </iframe> </div> </body> </html>
自定義比例
在 Bootstrap 中,自定義比例允許您使用 CSS 和 JavaScript 的組合為響應式元素定義您自己的縱橫比。
如果您有一個內建縱橫比修飾符類未涵蓋的特定縱橫比,這將非常有用。以下示例透過在.ratio上設定--bs-aspect-ratio: 50%來演示。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Ratio</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> <h1 class="text-success text-center"> Ratio </h1> <hr> <div class="text-center"> <h2 class="text-success">Bootstrap 5 Custom ratios</h2> </div> <br> <div class="ratio" style="--bs-aspect-ratio: 10%;"> <div class="bg-success"><h1>success</h1></div> </div> <div class="ratio" style="--bs-aspect-ratio: 30%;"> <div class="bg-secondary"><h1>secondary</h1></div> </div> </body> </html>
廣告