html中如何实现文本与标签居中显示
作者:admin 发布时间:2023-09-24 点击数:
1、文本居中:
text-align: center;
line-height: 100px; (=height)
2、标签居中
margin: 0 auto; // 其中0指的是 margin-top:0px;
3、具体代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生网页作业</title>
<style>
.item1{
height: 100px;
width: 100px;
background-color: red;
text-align: center;
line-height: 100px;
margin: 0 auto;
}
.item2{
height: 100px;
width: 100px;
background-color: wheat;
text-align: center;
line-height: 100px;
margin: 100px auto;
}
</style>
</head>
<body>
<div>
<div class="item1">1111</div>
<div class="item2">2222</div>
</div>
</body>
</html>