div:
1
2
3
4
border
:
1px
solid
red
;
margin
:
0
auto
;
height
:
50px
;
width
:
80px
;
浮动元素的上下左右居中:
1
2
3
4
5
6
7
8
border
:
1px
solid
red
;
float
:
left
;
position
:
absolute
;
width
:
200px
;
height
:
100px
;
left
:
50
%
;
top
:
50
%
;
margin
:
-
50px
0
0
-
100px
;
绝对定位的左右居中:
1
2
3
4
5
6
7
border
:
1px
solid
black
;
position
:
absolute
;
width
:
200px
;
height
:
100px
;
margin
:
0
auto
;
left
:
0
;
right
:
0
;
还有更加优雅的居中方式就是用flexbox,我以后会做整理。