以下 HTML...
<!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>
<title></title>
</head>
<body>
<div style="border: 1px solid blue;">
<div style="float: left;">
Expected NPV</div>
</div>
</body>
</html>
...呈现带有蓝色边框的父 DIV 和内部的子 DIV。但是, float :左;指令使父级不会用边框包围子级(这是我想要的)。
有没有办法在不移除 float:left 的情况下实现这一点?
我将 HTML 归结为一个非常简单的示例来说明基本问题。我意识到 float :左;在这个例子中是无意义的,但它是原始 HTML 所必需的。如果它更有帮助,我可以发布。
最佳答案
你可以给 parent 一个overflow
来考虑 child 的高度,像这样:
<div style="border: 1px solid blue; overflow: auto;">
<div style="float: left;">
Expected NPV</div>
</div>
You can test it here .如需完整说明,check out the excellent write-up on quirksmode.org .注意 overflow: hidden
在这里也有效,you can test that version here .
关于html - float 使 div 不包围 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3996639/