HTML: margin詳解

margin:10px;                設置塊元素的上,右,下,左方向的值同爲10px

margin:10px 30px;             設置塊元素的上和下爲10px,左和右爲30px;

margin:10px  20px 30px;          設置塊元素的上爲10px,右爲20px,下爲30px,左爲20px,未設置的元素margin值與對邊同

margin:10px 20px 30px 40px;        設置塊元素的上爲10px,右爲20px,下爲30px,左爲40px.

單獨對一個方向的margin值進行設置

margin-?

英文中上,右,下,左對應top,right,bottom,left
要設置一個方向上的margin值,只需要 margin- 開頭? 用top,right,bottom,left代替:

比如設置上外邊距: margin-top ,以此類推!

通過margin來左右居中

margin:auto;
margin:0 auto;
margin:15px auto;

注意:在 css 中只能左右居中,垂直居中往往需要用到js來控制(我就加個table>tr>td)。

原文地址:https://www.cnblogs.com/Zell-Dinch/p/4276051.html