1.text-align:center;
Centering by using the above method is to center the Display:inline in the parent container, and the inline element or text horizontally.
2.inline-height: (height) value;
When using inline-height, it is often used with the height, so that the content is centered vertically, it is recommended to use Li inside the list;
3.margin:auto;
When using margin to center, the element is usually given the exact width value, set the Margin:auto; or margin:0 auto; Is the same effect: the current element will be horizontally centered;
When using margin, you can also set the value of Margin-left and Margin-right equal, but also to achieve horizontal center;
4.position Positioning Center
Set by top and left or bottom, right to align elements horizontally and vertically, but parent elements must be set to height;
5.Flex Box
Flex-align:center of the Flex container;
Align-items:center;
Justify-cotent:center;
Align-self:center of project properties;
6. Negative margin:
1 . Box{2 width:600px;3 Height:400px;4 position:relative;5}6 7 . Box1{8 width:300px;9 Height:200px;Ten padding:20px; One position:Absolute; A Top:50%; - Left:50%; - Margin-left:-170px;/*(width+padding)/2*/ the Margin-top:-120px;/*(height+padding)/2*/ -}
The above code enables horizontal vertical centering of elements.
CSS Centering Method Summary