CSS Margin(外邊距)屬性定義元素周圍的空間。php
margin清除周圍的元素(外邊框)的區域。margin沒有背景顏色,是徹底透明的css
margin能夠單獨改變元素的上,下,左,右邊距。也能夠一次改變全部的屬性。html
值 | 說明 |
auto | 設置瀏覽器邊距。 這樣作的結果會依賴於瀏覽器 |
length | 定義一個固定的margin(使用像素,pt,em等) |
% | 定義一個使用百分比的邊距 |
Margin可使用負值,重疊的內容。瀏覽器
在CSS中,它能夠指定不一樣的側面不一樣的邊距:spa
margin-top:100px; margin-bottom:100px; margin-right:50px; margin-left:50px;
全部邊距屬性的縮寫屬性是"margin":ssr
margin:100px 50px;
margin屬性能夠有一到四個值。/p>code
margin:25px 50px 75px 100px;
orm
上邊距爲25pxhtm
右邊距爲50pxget
下邊距爲75px
左邊距爲100px
margin:25px 50px 75px;
上邊距爲25px
左右邊距爲50px
下邊距爲75px
margin:25px 50px;
上下邊距爲25px
左右邊距爲50px
margin:25px;
全部的4個邊距都是25px
文本的上邊距設置使用釐米值
這個例子演示瞭如何設置一個使用釐米值的文本的頂部margin。
Set 使用百分比值設置文本的下邊距
這個例子演示瞭如何設置使用百分比值的下邊距,相對於包含的元素的寬度。
屬性 | 描述 |
margin | 簡寫屬性。在一個聲明中設置全部外邊距屬性。 |
margin-bottom | 設置元素的下外邊距。 |
margin-left | 設置元素的左外邊距。 |
margin-right | 設置元素的右外邊距。 |
margin-top | 設置元素的上外邊距。 |