开发者

What is wrong with this html code?

开发者 https://www.devze.com 2023-02-11 11:52 出处:网络
<div style=\"float: left\">text1</div> <div style=\"float: right;\">text2</div>
<div style="float: left">text1</div> 
<div style="float: right;">text2</div>
<div class="random_class">text3&开发者_如何学运维lt;/div>

Here is the problem. Random_class goes to the top, on the text1 and 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/

Added clear:both; to .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. Floats are aware of other floats. Using clear:both; tells CSS that nothing should be to the left or right of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号