为什么我用 .txtCenter,{ text-align:center; } 在定宽块状元素,其会居中?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定宽块状元素水平居中</title>
<style>
div{
border:1px solid red;
width:400px;
}
.txtCenter{
text-align:center;
}
</style>
</head>
谢谢!
你的居中指的是文字的居中,并不是块状元素的居中
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定宽块状元素水平居中</title>
<style>
div{
border:1px solid red;
width:400px;
}
.txtCenter{
text-align:center;
}
</style>
</head>
<body>
<div class="txtCenter">我是定宽块状元素,我要水平居中显示。</div>
</body>
</html>