思路:
相当于父相子绝的原理:
给予一个float:left;来一个相对定位position: absolute;
左上50% ,其次transform: translate(-50%,-50%);
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
div{
float: left;
background-color: pink;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div>123</div>
</body>
</html>