html
<div class="content">
<div>我是内容</div>
</div>
第一种
.content
width: 300px;
height: 300px;
position: relative;
border: 1px solid #ccc;
div
display:inline-block;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
background-color: red;
![](https://i-blog.csdnimg.cn/blog_migrate/e9aebdc5fc9ec5789d50ff61ed34f1c0.png)
image.png
第二种
.content
width: 300px;
height: 300px;
border: 1px solid #ccc;
display: table-cell;
text-align: center;
vertical-align: middle;
div
display:inline;
background-color: red;
![](https://i-blog.csdnimg.cn/blog_migrate/49375db4c0d6b741c9c507f4de58c731.png)
image.png
第三种
.content
width: 300px;
height: 300px;
border: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
div
background-color: red;
![](https://i-blog.csdnimg.cn/blog_migrate/78056727784b745e0356a214e4df2bad.png)
image.png