不固定宽高块在浏览器中垂直水平居中
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>demo</title>
<style>
#content {
background:#eee;
position: absolute;
left:50%;
top:50%;
padding:20px 15px;
transform:translate(-50%,-50%);
}
</style>
</head>
<body>
<div id = "content">
<h1>这里是内容</h1>
<p>内容的宽高不定</p>
</div>
</body>
</html>
网友评论