简体   繁体   English

这个HTML代码有什么问题?

[英]What is wrong with this html code?

<div style="float: left">text1</div> 
<div style="float: right;">text2</div>
<div class="random_class">text3</div>

Here is the problem. 这是问题所在。 Random_class goes to the top, on the text1 and text2. Random_class在text1和text2上位于顶部。 What is wrong? 怎么了? Thank you. 谢谢。

You need to clear the floats, below is an example of it. 你需要清除浮动,下面是一个例子。

<div class="random_class" style="clear:both">text3</div>

You could also do 你也可以这样做

.random_class {
    clear: both
}

Here you go: 干得好:

http://jsfiddle.net/q4CqZ/3/ http://jsfiddle.net/q4CqZ/3/

Added clear:both; 添加clear:both; to .random_class .random_class

Whenever you float an element it takes it out of content flow. 无论何时浮动元素,它都会将其从内容流中移除。

Text1 and Text2 are floated so Text3 acts like it doesn't see it there. Text1和Text2是浮动的,因此Text3的行为就像它在那里看不到它一样。 Floats are aware of other floats. 浮子知道其他浮子。 Using clear:both; 使用clear:both; tells CSS that nothing should be to the left or right of it. 告诉CSS,它的左侧或右侧不应该是任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM