
- 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 - 特大標題演示
- 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 提供的一些類如下:。
.fixed-top
.fixed-bottom
.sticky-top
.sticky-bottom
讓我們看看每組類的示例。
固定頂部
類.fixed-top將元素的位置設定在視口的頂部,從邊緣到邊緣。
這對於建立導航欄或標題很有用,即使使用者向下滾動,這些導航欄或標題也會始終顯示在螢幕頂部。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html> <head> <title>Position - Fixed top</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 style="height:1500px"> <nav class="navbar navbar-expand-lg text-bg-success navbar-dark fixed-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Use of .fixed-top class</a> </div> </nav> <div class="container-fluid" style="margin-top:80px"> <h4>Position fixed at top</h4> <p>The class .fixed-top of Bootstrap sets the position of the element at top of the screen.</p> <h1>Scroll down the page to see the position</h1> </div> </body> </html>
固定底部
類.fixed-bottom將元素的位置設定在視口的底部,從邊緣到邊緣。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html> <head> <title>Position - Fixed bottom</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 style="height:1500px"> <nav class="navbar navbar-expand-lg text-bg-primary navbar-dark fixed-bottom"> <div class="container-fluid"> <a class="navbar-brand" href="#">Use of .fixed-bottom class</a> </div> </nav> <div class="container-fluid" style="margin-top:80px"> <h4>Position fixed at bottom</h4> <p>The class .fixed-bottom of Bootstrap sets the position of the element at the bottom of the page.</p> <h1>Scroll down the page to see the position</h1> </div> </body> </html>
粘性頂部
類.sticky-top用於建立粘性元素,該元素保留在螢幕頂部,從邊緣到邊緣,但僅在您滾動經過它之後。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Position - Sticky top</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 style="height:1500px"> <div class="container-fluid mt-3"> <h3>Sticky Navbar</h3> <p>The class <b>.sticky-top</b> is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p> <p>Scroll down the page to see the effect.</p> </div> <nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Sticky top</a> </div> </nav> <div class="container-fluid"> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> </div> </body> </html>
響應式粘性頂部
響應式粘性頂部類用於網頁設計,以建立導航選單或標題,當用戶向下滾動頁面時,該選單或標題會貼上到螢幕頂部。這確保了導航選單始終可見且易於訪問,即使使用者向下移動到頁面更下方。
Bootstrap 提供的一些響應式粘性頂部類如下
.sticky-sm-top 將元素(s) 的位置貼上到小型視口頂部
.sticky-md-top 將元素(s) 的位置貼上到中等大小的視口頂部
.sticky-lg-top 將元素(s) 的位置貼上到大型視口頂部
.sticky-xl-top 將元素(s) 的位置貼上到特大型視口頂部
.sticky-xxl-top 將元素(s) 的位置貼上到超特大型視口頂部
讓我們看一個例子
注意:調整瀏覽器大小以檢視更改。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html lang="en"> <head> <title>Position - Responsive Sticky top</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 style="height:1500px"> <div class="container-fluid mt-3"> <h3>Sticky Navbar</h3> <p>The class <b>.sticky-lg-top</b> is a responsive class, used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p> <p>Scroll down the page to see the effect.</p> </div> <nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-lg-top"> <div class="container-fluid"> <a class="navbar-brand" href="#">Responsive Sticky top</a> </div> </nav> <div class="container-fluid"> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> <p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p> </div> </body> </html>
粘性底部
類.sticky-bottom用於建立粘性元素,該元素保留在螢幕底部,從邊緣到邊緣,但僅在您滾動經過它之後。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html> <head> <title>Position - sticky bottom</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 style=height:1000px class="d-flex flex-column"> <!-- Navbar --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Sticky Bottom Example</a> </div> </nav> <!-- Content --> <div class="container-fluid flex-grow-1"> <h4>sticky bottom</h4> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> </div> <!-- Sticky Footer --> <footer class="footer text-bg-info py-3 sticky-bottom"> <div class="container"> <span class="display-6 text-dark">Sticky bottom</span> </div> </footer> </body> </html>
響應式粘性底部
Bootstrap 提供的一些響應式粘性底部類如下
.sticky-sm-bottom 將元素(s) 的位置貼上到小型視口底部
.sticky-md-bottom 將元素(s) 的位置貼上到中等大小的視口底部
.sticky-lg-bottom 將元素(s) 的位置貼上到大型視口底部
.sticky-xl-bottom 將元素(s) 的位置貼上到特大型視口底部
.sticky-xxl-bottom 將元素(s) 的位置貼上到超特大型視口底部
讓我們看一個響應式粘性底部類的示例
注意:調整瀏覽器大小以檢視更改。
示例
您可以使用編輯和執行選項編輯並嘗試執行此程式碼。
<!DOCTYPE html> <html> <head> <title>Position - Responsive sticky bottom</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 style=height:1000px class="d-flex flex-column"> <!-- Navbar --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#">Responsive Sticky Bottom Example</a> </div> </nav> <!-- Content --> <div class="container-fluid flex-grow-1"> <h4>Responsive sticky bottom</h4> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> <p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p> </div> <!-- Sticky Footer --> <footer class="footer text-bg-warning py-3 sticky-lg-bottom"> <div class="container"> <span class="display-6 text-dark">Sticky bottom</span> </div> </footer> </body> </html>