Home  >  Article  >  Web Front-end  >  [CSS] The floating thing

[CSS] The floating thing

WBOY
WBOYOriginal
2016-07-21 14:52:59944browse

How elements float

The horizontal direction of the element floats, which means that the element can only move left and right but not up and down.

A floated element will move as far left or right as possible until its outer edge touches the border of the containing box or another floated box.

Elements after the floated element will surround it.

Elements before the floated element will not be affected.

Text

Floating is a state that is semi-detached from the document flow. It is not completely detached from the document flow like absolute positioning

Absolute positioning:

 


 

 

 

At this time, div1 has no height set. Although the height is set to 100px in div2, div2 cannot support the height of div1 because the absolute positioning is completely out of the document flow, and div1 cannot feel div2 at all;

Floating: the first case

 


 

 

 

We have set a left float in div2. If you do not clear the impact of div2's floating in div1, then you will not be able to expand the height of div1 because div1 cannot feel the floating.

But after you clear the float, div1 can feel the existence of the float (equivalent to the float now being in the document flow), and the height will be expanded.

Here are two solutions

 

 

Floating: the second case

 

Crazy and eccentric


 

 

Because the float (div2) can feel the

here, it can be displayed as it should; that is, the elements before the floating element will not be affected.

 

Floating: The third case

 


 

Psychosis

 

 

cannot feel the existence of float (div2), then

will be covered by float, but it is not completely covered.

We can find that the background of

is indeed covered, but the text content of

is not covered. This is also a weird thing about floating - floating will not cover the text in the document flow, but Other properties will be overridden.

Solution

Set a clear:left; for

to clear the effect of floating, so that

can feel the existence of (div2).

 


 

Crazy and crazy

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:A very good FLASH plug-inNext article:A very good FLASH plug-in