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)。

 

相关文章:

  • 2021-12-22
  • 2021-11-21
  • 2021-06-26
  • 2022-02-02
  • 2022-01-31
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-01
  • 2021-06-28
  • 2021-07-18
  • 2021-05-31
  • 2021-09-08
  • 2021-09-05
  • 2022-12-23
相关资源
相似解决方案