DIV CSS 佈局教程網

CSS left、right、top、bottom 定位屬性
編輯:布局基本知識     

CSS 定位偏移屬性

CSS left、right、top、bottom 通常用來控制定位元素的偏移位置。它們本身不會單獨生效,必須搭配 position 屬性使用。

基本語法

left: 20px;
right: 20px;
top: 20px;
bottom: 20px;

left 表示距離左側多遠,right 表示距離右側多遠,top 表示距離頂部多遠,bottom 表示距離底部多遠。

使用條件

這些屬性通常搭配:

position: relative;
position: absolute;
position: fixed;

如果沒有設定 position,left、right、top、bottom 很可能不會產生預期效果。

注意事項

同一元素通常不建议同時設定 left 與 right,或同時設定 top 與 bottom,否則可能造成定位邏輯衝突。實務上多半只選擇其中一組方向。

小結

left、right、top、bottom 是定位系統中的偏移工具。只要搭配正確的 position,就能精準控制元素位置。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved