嵌套的DIV元素

xra*_*inx 19 html css xhtml

我试图在包装DIV(纯绿色边框)内包含两个DIV元素,内部1和内部2(点缀红色边框),但包装器DIV元素不会展开以包围内部DIV.

我究竟做错了什么?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Nested divs </title>
</head>

<body>
<div id="wrapper" style="margin-left:auto; margin-right:auto; border:solid #669933;"> 
  content inside "wrapper" div
  <div id="inner-1" style="float:left; width:49%; border:dotted #CC3300;">
    content <br />
    inside <br />
    inner-1 div
  </div>

  <div id="inner-2" style="float:left; width:49%; border:dotted #CC3300;"> 
    content inside inner-2 div 
  </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

呈现HTML

mof*_*off 32

既然你都漂浮#inner-1#inner-2,你需要一个明确的修复.基本上,设置overflow: auto父(#wrapper)应该做的伎俩.