我有以下代码(可用于测试运行here):我可以浮动div并仍然保持它的布局?
<div style="margin:10px">
<div class="alert-message block-message warning">
<h3>Hello World</h3>
<p>You're about to take an action which cannot be undone.</p>
<form method="post" action style="float:right">
<button class="btn danger" type="submit">For Reals!</button>
<a href="#" class="btn">Nah.</a>
</form>
</div>
</div>
上述点是有具有表单控件浮在警报的右下角中背景框。
不幸的是,正如你在例子中看到的那样,表单项显然不包含在布局中,因为背景没有扩展到覆盖它们。有没有解决的办法?
您可以查看编辑页面在这里:http://jsdo.it/rfkrocktk/h5IL
参见:http://stackoverflow.com/questions/211383/which-method-of-clearfix-is-best当你漂浮的元素,它改变了包含元素的尺寸(在许多情况下)。 –
我认为处理这个问题的一个常用方法是添加一个隐藏的div区域,它清除所有浮点数... – jswolf19