css – 嵌套DIV元素

前端之家收集整理的这篇文章主要介绍了css – 嵌套DIV元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正试图封闭两个DIV元素,内部1和内部2,(虚线红色边框)在包装器DIV(实心绿色边框)内,但包装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>

Rendered HTML

解决方法

因为你同时浮动#inner-1和#inner-2,所以你需要一个 clear fix.基本上,设置overflow:auto在父(#wrapper)上应该做的伎俩。
原文链接:https://www.f2er.com/css/218673.html

猜你在找的CSS相关文章