为什么子div长宽会超出父div呢?
html:
<div id="box">
<div id="box_child">
</div>
<div id="box_child">
</div>
</div>
css:
#box{
width: 690px;
height:600px;
background-color:#f99;
margin:0 auto;
float:left;
margin-top:30px;
}
#box_child{
width: 680px;
height:200px;
background-color:#f90;
margin:0 auto;
float:left;
margin-top:30px;
padding:50px;
}
子div的长宽定义时比父div小,为什么显示却超出父div很多?
[解决办法]
padding:50px;没算进去吧。
#box_child的实际宽度是 680px+50px*2=780px.
[解决办法]
<!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>无标题文档</title>
<style type="text/css">
#box{
float:left;
width: 100%;
height:100%;
background-color:#f99;
margin-top:30px;
}
.box_child{
float:left;
width: 680px;
height:200px;
background-color:#f90;
margin-top:30px;
padding:50px;
}
</style>
</head>
<body>
<div id="box">
<div class="box_child"></div>
<div class="box_child"></div>
</div>
</body>
</html>