我怎样才能处理崩溃的父母?

时间:2011-06-17 11:07:27

标签: html css

当我没有指定高度时,父级会崩溃。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css" >
#parent{width:500px;border:#000 thin groove}

#parent p{float:left}

</style>
</head>

<body>

<div id="parent">
<p height="100px" width="100px">text</p>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:3)

overflow: hidden添加到您的#parent div

有关其工作原理的说明是http://www.quirksmode.org/css/clearing.html