<!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>
*{
margin: 0px;
padding: 0px;
}
.main{
margin: 100px auto;
height: 20px;
width: 300px;
background-color: aquamarine;
}
.main span{
display: inline-block;
line-height: 20px;
background-color: rebeccapurple;
}
</style>
</head>
<body>
<div class="main">
<span>我的地盘</span>
</div>
</body>
</html>
我想说的是垂直怎么不是居中
.main span{
display: block;
line-height: 20px;
background-color: rebeccapurple;
}
在.main加个文本居中 text-align: center;
.main {
margin: 100px auto;
height: 20px;
width: 300px;
background-color: aquamarine;
text-align: center;
}