CSS Margin(外邊距)
一、簡介
CSS margin(外邊距)屬性定義元素周圍的空間。
margin 清除周圍的(外邊框)元素區域。margin 沒有背景顏色,是完全透明的。
margin 可以單獨改變元素的上,下,左,右邊距,也可以一次改變所有的屬性。

margin 屬性值:

Margin可以使用負值,重疊的內容。
二、Margin - 單邊外邊距屬性
在CSS中,它可以指定不同的側面不同的邊距:
margin-top:100px;
margin-bottom:100px;
margin-right:50px;
margin-left:50px;
三、Margin - 簡寫屬性
為了縮短代碼,有可能使用一個屬性中margin指定的所有邊距屬性。這就是所謂的簡寫屬性。
所有邊距屬性的簡寫屬性是 margin :
margin:100px 50px;
margin屬性可以有一到四個值。
- margin:25px 50px 75px 100px;
- 上邊距為25px
- 右邊距為50px
- 下邊距為75px
- 左邊距為100px
- margin:25px 50px 75px;
- 上邊距為25px
- 左右邊距為50px
- 下邊距為75px
- margin:25px 50px;
- 上下邊距為25px
- 左右邊距為50px
- margin:25px;
- 所有的4個邊距都是25px
四、所有的CSS邊距屬性

五、示例
(1)示例1:設置一個使用厘米值的文本的頂部margin
p.ex1 {margin-top:2cm;} /*一個2厘米上邊距的段落*/
(2)示例2:設置使用百分比值的下邊距,相對於包含的元素的寬度
p.bottommargin {margin-bottom:25%;}
