校招刷题群
高效刷题 迎战校招
校招精选试题
近年面笔经面经群内分享
Java刷题群 前端刷题群 产品运营群
首页 > js语言和框架 > 水平、垂直居中
题目

CSS实现垂直水平居中

解答

一道经典的问题,实现方法有很多种,以下是其中一种实现:

HTML结构:

<div class="wrapper">
<div class="content"></div>
</div>

CSS:

.wrapper{position:relative;}
.content{
background-color:#6699FF;
width:200px;
height:200px;
position: absolute; //父元素需要相对定位
top: 50%;
left: 50%;
margin-top:-100px ; //二分之一的height,width
margin-left: -100px;
}


C 1条回复 评论
Peach

清晰直白,真不戳

发表于 2022-07-11 21:00:00
0 0