DIV+CSS如何让文字垂直居中?

来源:百度知道 编辑:UC知道 时间:2024/06/18 09:46:29
我给div标签加了一个css想让div标签里的文字垂直居中对齐,该怎么做?
<div class="1_div ">知识天地</div>
.1_div {
font-size: 12px;
font-weight: bold;
color: #FF6600;
text-indent: 10px;
background-color: #DAEEF8;
line-height: 24px;
height: 24px;
}

<html>
<head>
<title>DIV+CSS如何让文字垂直居中</title>
<style type="text/css">
.div_1 {
font-size: 12px;
font-weight: bold;
color: #FF6600;
text-indent: 10px;
background-color: #DAEEF8;
padding-top:6px;/*(24-12)/2;height减font-size然后除以2*/
height:24px;
}
</style>
</head>
<body>
<div class="div_1 ">知识天地</div>
</body>
</html>

你的代码是对的,只不过class命名有问题。

<style>
.aa{
font-size: 12px;
font-weight: bold;
color: #FF6600;
text-indent: 10px;
background-color: #DAEEF8;
line-height: 24px;
height: 24px;
}
</style>

<div class="aa">知识天地</div>

text-align:center;

align=center valign=middle 垂直距离 halign=水平距离 (top middle bottom baseline基线)