
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - Clearfix
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 平移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 疊加層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - all
- CSS - inset
- CSS - isolation
- CSS - overscroll
- CSS - justify-items
- CSS - justify-self
- CSS - tab-size
- CSS - pointer-events
- CSS - place-content
- CSS - place-items
- CSS - place-self
- CSS - max-block-size
- CSS - min-block-size
- CSS - mix-blend-mode
- CSS - max-inline-size
- CSS - min-inline-size
- CSS - offset
- CSS - accent-color
- CSS - user-select
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - box-decoration-break
- CSS - caret-color
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - box-sizing
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - bottom 屬性
CSS bottom 屬性用於設定已定位元素的底部位置。它指定元素底部邊緣與其容器元素底部邊緣之間的距離。position屬性的值決定了bottom屬性的效果。
語法
bottom: auto | length | percentage | initial | inherit;
屬性值
值 | 描述 |
---|---|
auto | 讓瀏覽器計算元素的底部邊緣位置。預設值。 |
長度 | 以長度單位設定元素的底部邊緣位置(例如 10px、20px 等)。負值有效。 |
百分比 | 以容器元素的百分比設定元素的底部邊緣位置(例如 10%、20% 等)。負值有效。 |
initial | 將屬性設定為其預設值。 |
inherit | 從父元素繼承該屬性。 |
CSS 邊框屬性示例
以下示例解釋了使用不同值的bottom屬性。
使用絕對定位的 Bottom 屬性
要將bottom屬性與absolute(絕對)位置一起使用,元素必須包含在一個本身已定位的父元素中。然後,元素將相對於父元素進行定位。可以以長度或百分比值(例如 10px、20% 等)或 auto 值指定距父容器邊緣底部的距離。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .container { position: relative; background-color: lightgray; height: 400px; } .boxes{ position: absolute; border: 3px solid black; padding: 10px; width: 20%; } .box { bottom: 150px; background-color: lightcoral; } .box2{ bottom: 10%; background-color: lightgreen; } .box3{ bottom: auto; background-color: lightblue; } </style> </head> <body> <h2> CSS bottom property </h2> <p> Position: Absolute, the absolute position places the element relative to its positioned parent element. </p> <p> For all the boxes, the parent is the grey container with 'relative' position, so it they have been placed at 10%, 150px and auto from the bottom edge of their parent. </p> <div class="container"> <div class=" boxes box"> Position: Absolute, bottom: 150px </div> <div class=" boxes box2"> Position: Absolute, bottom: 10% </div> <div class="boxes box3"> Position: Absolute, bottom: auto </div> </div> </body> </html>
使用相對定位的 Bottom 屬性
當bottom屬性與relative(相對)位置一起使用時,元素將相對於其正常位置進行定位。可以以長度或百分比值(例如 10px、20% 等)或 auto 值指定距其正常位置底部的距離。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .container { position: relative; background-color: lightgray; height: 300px; } .boxes { position: relative; border: 3px solid black; padding: 10px; width: 20%; } .box { bottom: auto; background-color: lightcoral; } .box2 { bottom: 55%; background-color: lightgreen; } .box3 { bottom: 25px; background-color: lightblue; } </style> </head> <body> <h2> CSS bottom property </h2> <p> Position: Relative, the relative position places the element relative to its normal position. </p> <p> For all the boxes, the parent is the grey container with 'relative' position, so they have been placed at 25px, auto and 55% from their normal positions. </p> <br/><br/><br/><br/> <div class="container"> <div class=" boxes box"> Position: Relative, bottom: auto </div> <div class=" boxes box2"> Position: Relative, bottom: 55% </div> <div class="boxes box3"> Position: Relative, bottom: 25px </div> </div> </body> </html>
使用固定定位的 Bottom 屬性
fixed(固定)位置將元素放置在特定位置,即使滾動頁面,元素也會保持在該位置。可以以長度或百分比(例如 10px、20% 等)或 auto 值指定元素距底部的距離。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .container { position: relative; background-color: lightgray; height: 700px; } .boxes { position: fixed; border: 3px solid black; padding: 10px; width: 20%; } .box { bottom: auto; background-color: lightcoral; } .box2 { bottom: 75px; background-color: lightgreen; } .box3 { bottom: 2%; background-color: lightblue; } </style> </head> <body> <h2> CSS bottom property </h2> <p> Position: Fixed, the fixed position places the element at a fixed position even during a scroll. </p> <p> For all the boxes, the parent is the grey container with 'relative' position, so they have been placed at auto, 75px and 2% from the parent's bottom edge. </p> <div class="container"> <div class=" boxes box"> Position: Fixed, bottom: auto </div> <div class=" boxes box2"> Position: Fixed, bottom: 75px </div> <div class="boxes box3"> Position: Fixed, bottom: 2% </div> </div> </body> </html>
使用粘性定位的 Bottom 屬性
粘性定位使元素在滾動經過指定點時相對於其容器保持固定。使用bottom屬性,我們可以控制距容器底部邊緣的距離。auto、10px 或 10% 等值會相應地調整其粘性行為。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .container { position: relative; background-color: lightgray; height: 100vh; } .boxes { position: sticky; border: 3px solid black; padding: 10px; width: 20%; } .box { bottom: auto; background-color: lightcoral; } .box2 { bottom: 10px; background-color: lightgreen; } .box3 { bottom: 10%; background-color: lightblue; } </style> </head> <body> <h2> CSS Bottom Property with Sticky Position </h2> <p> Position: Sticky, the bottom property affects how the element sticks to its container's bottom edge. </p> <p> The parent container has a height of 700px, so the sticky elements are positioned at auto, 10px, and 10% from the container's bottom edge. </p> <div class="container"> <div class="boxes box"> Position: Sticky, bottom: auto </div> <div class="boxes box2"> Position: Sticky, bottom: 10px </div> <div class="boxes box3"> Position: Sticky, bottom: 10% </div> </div> </body> </html>
注意:'static'(靜態)位置不受 top、right、bottom 或 left 屬性的影響。它按元素出現的順序顯示元素。這是元素的預設位置。
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
bottom | 1.0 | 5.0 | 1.0 | 1.0 | 6.0 |
css_properties_reference.htm
廣告