Html 我怎样才能停止向左浮动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6205191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I stop float left?
提问by TonyG
I have the following code:
我有以下代码:
<div style="float: left; width: 100%;">
<label style="float: left;">ABC</label>
<input style="float: left; font-size: 0.5em;" type="button" onclick="addTiny(0,'Question_Text'); return false;" value="▼" title="Editor" />
<input style="float: left; font-size: 0.5em;" type="button" onclick="remTiny(0,'Question_Text'); return false;" value="▲" title="Hide" />
<div class="adm">
<textarea rows="2;" style="width: 100%" class="text-box multi-line mceEditor">
abc
</textarea>
</div>
</div>
My problem is that the div with class adm floats to the left and so goes on the same line as the label and two input buttons. Is there a way that I can make this shift away from floating?
我的问题是带有类 adm 的 div 向左浮动,因此与标签和两个输入按钮位于同一行。有没有办法让我摆脱漂浮的转变?
回答by Shad
A standard approach is to add a clearing div between the two floating block level elements:
一种标准方法是在两个浮动块级元素之间添加一个清除 div:
<div style="clear:both;"></div>
回答by DanKodi
Sometimes clear will not work. Use float: none
as an override
有时清除不起作用。使用float: none
作为覆盖
回答by Brett
You could modify .adm
and add
您可以修改.adm
和添加
.adm{
clear:both;
}
That should make it move to a new line
这应该使它移动到一个新的行
回答by tjm
add style="clear:both;"
to the "adm" div
.
添加style="clear:both;"
到“adm” div
。
回答by TonyG
Okay I just realized the answer is to remove the first float left from the first DIV. Don't know why I didn't see that before.
好吧,我刚刚意识到答案是从第一个 DIV 中删除剩下的第一个浮点数。不知道为什么我之前没有看到。
回答by Trey
You should also check out the "clear" property in css in case removing a float isn't an option
您还应该检查 css 中的“clear”属性,以防删除浮点数不是一种选择
回答by Chris Kent
The css clear: left
in your adm class should stop the div floating with the elements above it.
clear: left
adm 类中的 css应该阻止 div 与其上方的元素一起浮动。
回答by sunny
Just add overflow:hidden
in the first div
style. That should be enough.
只需添加overflow:hidden
第一种div
样式。那应该就够了。