
- 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 - 清除浮動
- 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 雙向演算法
- 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 - 二維變換
- CSS - 三維變換
- 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 - left 屬性
CSS left 屬性用於指定已定位元素相對於其容器元素的水平位置。它確定元素的左邊緣位置。根據position 屬性的值,確定left 屬性的效果。
語法
left: auto | length | percentage | initial | inherit;
屬性值
值 | 描述 |
---|---|
auto | 瀏覽器計算左位置。預設值。 |
長度 | 它以長度單位 (px、em、rem 等) 指定左邊緣位置。允許負值。 |
百分比 | 它相對於容器元素指定左邊緣位置的百分比。允許負值。 |
initial | 它將屬性設定為其預設值。 |
inherit | 它從父元素繼承屬性。 |
CSS Left 屬性示例
以下示例說明了具有不同值的left 屬性。
使用絕對定位的 Left 屬性
使用position: absolute,left 屬性確定元素左邊緣到最近的已定位祖先元素的水平距離。如果不存在已定位祖先元素,則從初始包含塊進行定位。這在以下示例中顯示。使用了不同的距離單位。
示例
<!DOCTYPE html> <html> <head> <style> .box { background-color: lightgreen; padding: 10px; color: green; } .absolute-box { font-weight: bold; position: absolute; width: 130px; height: 50px; padding: 2px; border: 3px solid green; background-color: #bbedbb; color: #e50c0c; } .left { left: 0; } .left-px { left: 60px; } .left-per { left: 30%; } .left-em { left: 4em; } .left-auto { left: auto; } </style> </head> <body> <h2> CSS left property </h2> <h4> position: absolute </h4> <div class="box"> <div class="absolute-box left"> position:absolute; left: 0; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="absolute-box left-px"> position:absolute; left: 60px; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="absolute-box left-per"> position:absolute; left: 30%; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="absolute-box left-em"> position:absolute; left: 4em; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="absolute-box left-auto"> position:absolute; left: auto; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. </div> </body> </html>
使用固定定位的 Left 屬性
使用position: fixed,left 屬性設定元素距視口左邊緣的距離。即使在頁面滾動期間,元素也保持其位置。這在以下示例中顯示。使用了不同的距離單位。
示例
<!DOCTYPE html> <html> <head> <style> .box { background-color: lightgreen; padding: 10px; color: green; } .fixed-box { font-weight: bold; position: fixed; width: 130px; height: 50px; padding: 2px; border: 3px solid green; background-color: #bbedbb; color: #e50c0c; } .left-px { left: 60px; } .left-per { left: 30%; } .left-auto { left: auto; } </style> </head> <body> <h2> CSS left property </h2> <h4> position: fixed </h4> <div class="box"> <div class="fixed-box left-px"> position: fixed; left: 60px; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="fixed-box left-per"> position: fixed; left: 30%; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="fixed-box left-auto"> position: fixed; left: auto; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. </div> </body> </html>
使用相對定位的 Left 屬性
使用position: relative,left 屬性相對於正常位置定位元素。如果給出正值,元素向右移動;如果給出負值,元素向左移動,而不會影響其他元素。這在以下示例中顯示。使用了不同的距離單位。
示例
<!DOCTYPE html> <html> <head> <style> .box { background-color: lightgreen; padding: 10px; color: green; } .relative-box { font-weight: bold; position: relative; width: 130px; height: 50px; padding: 2px; border: 3px solid green; background-color: #bbedbb; color: #e50c0c; } .left { left: 0; } .left-px { left: 60px; } .left-per { left: 30%; } .left-em { left: 4em; } .left-auto { left: auto; } </style> </head> <body> <h2> CSS left property </h2> <h4> position: relative </h4> <div class="box"> <div class="relative-box left"> position: relative; left: 0; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="relative-box left-px"> position: relative; left: 60px; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="relative-box left-per"> position: relative; left: 30%; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="relative-box left-em"> position: relative; left: 4em; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="relative-box left-auto"> position: relative; left: auto; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. </div> </body> </html>
使用靜態定位的 Left 屬性
使用position: static,left 屬性無效,元素根據正常的文件流進行定位。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> .box { background-color: lightgreen; padding: 10px; color: green; } .static-box { font-weight: bold; position: static; width: 130px; height: 50px; padding: 2px; border: 3px solid green; background-color: #bbedbb; color: #e50c0c; } .left { left: 0; } .left-px { left: 60px; } .left-per { left: 30%; } .left-em { left: 4em; } .left-auto { left: auto; } </style> </head> <body> <h2> CSS left property </h2> <h4> position: static </h4> <div class="box"> <div class="static-box left"> position: static; left: 0; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="static-box left-px"> position: static; left: 60px; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="static-box left-per"> position: static; left: 30%; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="static-box left-em"> position: static; left: 4em; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="static-box left-auto"> position: static; left: auto; </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. </div> </body> </html>
使用粘性定位的 Left 屬性
使用position: sticky,left 屬性控制元素在其包含塊內的位置,直到達到定義的閾值。在滾動期間超過此閾值後,元素的行為就像它被固定一樣,粘附在 left 屬性定義的位置。這在以下示例中顯示。使用了不同的距離單位。
示例
<!DOCTYPE html> <html> <head> <style> .box { background-color: lightgreen; color: green; padding: 10px; } .sticky-container { position: relative; } .sticky-box { position: sticky; width: 130px; height: 60px; padding: 2px; border: 3px solid green; background-color: #bbedbb; color: #e50c0c; font-weight: bold; top: 10px; } .left { left: 40px; } </style> </head> <body> <h2> CSS left property </h2> <h4> position: sticky </h4> <div class="box"> <div class="sticky-container"> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. <div class="sticky-box left"> position: sticky; left: 40px. </div> TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. TutorialsPoint is a versatile online educational platform that provides a vast array of free tutorials and courses across numerous subjects,such as programming, web development, data science, and more. It caters to learners of all levels, offering detailed explanations, practical examples, and interactive exercises to enhance understanding and skills.Ideal for self-paced learning and skill development. </div> </div> </body> </html>
position 值 | Bottom 屬性 |
---|---|
absolute 或 fixed | 它指定元素左邊緣的外邊距和容器左邊緣內邊框之間的距離。 |
relative | 它指定元素左邊緣從其正常位置向右移動的距離。 |
sticky | 當元素在視口中時,該屬性的行為類似於其位置為 relative;當元素在視口外時,該屬性的行為類似於其位置為 fixed。 |
static | left 屬性對元素沒有影響。 |
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
left | 1.0 | 5.5 | 1.0 | 1.0 | 5.0 |
css_properties_reference.htm
廣告