<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>居中</title>
<style>
#center{
text-align:center;
vertical-align:middle;
height:200px;
line-height:200px;
width:400px;
border:#000000 dotted 1px;
}
</style>
</head>
<body>
<div id="center">hello,i am center</div>
</body>
</html>
height和line-heigt的值相同的话就是在div中垂直居中了。再加上text-aign:center是水平居中。
来看看效果吧:
hello,i am center