嵌套DIV元素 [英] Nested DIV elements
本文介绍了嵌套DIV元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图包含两个DIV元素,内部1&内部-2,(虚线红色边框)在包装器DIV(纯绿色边框)内部,但是包装器DIV元素不会展开以包围内部DIV。
I am trying to enclose two DIV elements, inner-1 & inner-2, (dotted red border) inside a wrapper DIV (solid green border) but the wrapper DIV element does not expand to enclose the inner DIVs.
做错了?
<!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>
推荐答案
因为你浮动 #inner -1
和#inner-2
,您需要一个清除修正。基本上,在父级( #wrapper
)上设置 overflow:auto
应该做的。
Since you're floating both #inner-1
and #inner-2
, you'll need a clear fix. Basically, setting overflow: auto
on the parent (#wrapper
) should do the trick.
这篇关于嵌套DIV元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文