-
文字水平居中:
text-align: center;
-
块级元素居中(水平和垂直):
display: flex; justify-content: center; align-items: center;
-
水平居中:
margin-left: auto; margin-right: auto;
-
垂直居中:
display: flex; align-items: center; justify-content: center; flex-direction: column;
-
行内元素居中:
display: inline-block; text-align: center; vertical-align: middle; line-height: normal;
-
背景图片居中:
background-image: url('path/to/image.jpg'); background-size: cover; background-position: center center;
需要注意的是,不同的居中方式适用于不同的元素和场景,具体使用需要根据实际情况进行选择。