一个div在未知父级width和height时,在父级中“垂直水平居中”的css代码。
父级:body
子级:wrap
.wrap{
width: 473px;
height: 484px;
background-color: red;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
如果父级是其他的div,记得要加position: relative;
position: relative;