Before too many ways to sum up the middle level, but today see a characteristic margin, the line of code to get very practical "css World" this book, share
margin: auto
Automatically fill the remaining width and height is set after the width and height of block elements. margin: auto
Prerequisite for the automatic filling element is triggered automatically populated with the corresponding characteristics in the horizontal or vertical direction, the default height is clearly the case that the block elements do not have this condition. Typical applications are implemented in the block element level Bureau of:
display: block;
width: 200px;
margin: 0 auto;
auto
Feature is that if both sides auto
, both the average remaining width; if one side margin
is fixed, the other side is auto
, the side of auto
the remaining width. Examples ↓
It is not very convenient
Of course, in addition to the horizontal direction and the vertical direction margin
can be realized vertically centered, but requires elements with automatic filling properties in the vertical direction, and this characteristic can be utilized position
to realize:
.mm>div{
position: absolute;
left: 0; right: 0; top: 0; bottom: 0;
width: 200px;
height: 200px;
margin: auto;}