<!DOCTYPE html>
<html>
<head>
<title>垂直水平居中</title>
<meta charset="utf-8">
<style>
.wrap{
background-color: #ccc;
}
.test {
background-color: red;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50% -50%);
}
</style>
</head>
<body>
<div class="wrap">
<div class="test">
水平垂直居中<br>
两行文字
</div>
</div>
</body>
</html>
未知高度宽度元素垂直水平居中
最新推荐文章于 2022-09-01 20:16:38 发布