你的位置:首页 > 网页设计

[网页设计]高度塌陷问题


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title></title>

<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
.first{
margin:20px;
background:lightgreen;
border: 2px solid lightgreen;
/*display:inline-block;*/
/*overflow:hidden;*/
/*float: left;*/如果选择这种方法,一定要在该元素的下个元素添加clear:both,
/*position: absolute;*/

}
ul{
overflow:hidden;
margin:10px;
background:lightblue;
width:100px;
height:200px;
float: left;
}
li{
margin:25px;
}
</style>


</head>

<body >
<div >
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>

<!--<div ></div>-->
</div>

</body>

</html>

父元素未设置高度和宽度的时候。那么它的高度就会塌缩为零,前提是它只包含浮动元素,解决高度塌陷的问题很简单,可以浮动父级元素、清除法等等,均可实现