解决DIV的高度设置问题

根据div+css网页布局的需要,我们有时候需要设置容器的高度为1px。而设置后在IE中预览,并不是所设置的样子,好象容器被撑开了,达不到想要的最小高度。
其实这是IE的默认行高所引起的,解决的方法也有很多,下面我们例举了overflow:hidden、line-heigh两种方法。

overflow:hidden实现div最小高度

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IT130.cn</title>
<style type="text/css">
<!--
#YourHomePage_com_cn {
 width:100%;
 height:1px;
 background:#c00;
 overflow:hidden;
 }
-->
</style>
</head>
<body>
<div id="YourHomePage_com_cn"> </div>
</body>
</html>

line-height实现div最小高度

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IT130.cn</title>
<style type="text/css">
<!--
#YourHomePage_com_cn {
 width:100%;
 height:1px;
 background:#c00;
 line-height:1px;
 }
-->
</style>
</head>
<body>
<div id="YourHomePage_com_cn"> </div>
</body>
</html>

posted on 2007-10-27 13:17  西湖浪子  阅读(2514)  评论(0)    收藏  举报