Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:position:inherit?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>文字水平垂直居中</title>
<style type="text/css">
.box{
width:20em;
height: 30em;
background-color: red;
/*设置文字在盒子中水平居中显示*/
text-align: center;
/*设置文字在盒子的垂直居中显示*/
line-height:30em;
}
</style>
</head>
<body>
<div class="box">我是box</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定位实现盒子的水平垂直居中</title>
<style type="text/css">
.parent{
position: relative;
background-color: yellow;
border: 1px solid;
width:25em;
height: 25em;
}
.box{
position: absolute;
top:0;
bottom: 0;
left:0;
right: 0;
margin: auto;
background-color: red;
width:15em;
height: 15em;
text-align: center;
line-height: 15em;
}
</style>
</head>
<body>
<div class="parent">
<div class="box">我是box</div>
</div>
</body>
</html>