<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
width: 800px;
height: 200px;
background-color: pink;
/* margin: 0 auto; */
overflow: hidden;
position: relative;
}
div div {
/* line-height: 200px; */
/* margin: 70px; */
/* padding: 80px; */
background-color: green;
width: 200px;
height: 20px;
/* margin: 0 auto; */
position: absolute;
top: 45%;
left: 40%;
/* margin-top: 80px; */
}
</style>
</head>
<body>
<div>
<div>你好世界</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
width: 300px;
/* height: 300px; */
background-color: green;
}
div div {
width: 200px;
height: 200px;
background-color: pink;
/* position: absolute; */
float: left;
}
.clearfix {
clear: both;
}
</style>
</head>
<body>
<div>
<div></div>
<p class="clearfix"></p>
</div>
</body>
</html>
参考https://blog.csdn.net/wuguidian1114/article/details/105559117