Home >Web Front-end >CSS Tutorial >How to make CSS float

How to make CSS float

(*-*)浩
(*-*)浩Original
2019-12-20 15:30:434013browse

How to make CSS float

A floating box can be moved left or right until its outer edge touches the border of the containing box or another floating box.

Because the floated box is not in the document's normal flow, a block box in the document's normal flow behaves as if the floated box does not exist.

CSS floating, in CSS, we realize the floating of elements through the float attribute.                                                                                                                                                                                                                               (Recommended learning: CSS tutorial)

Please look at the picture below. When box 1 is floated to the right, it breaks away from the document flow and moves to the right until its right edge Hitting the right edge of the containing box:

How to make CSS float

Look at the picture below again. When box 1 floats to the left, it breaks away from the document flow and moves to the left until its left The edge touches the left edge of the containing box. Because it is no longer in the document flow, it takes up no space and actually covers box 2, causing box 2 to disappear from view.

If all three boxes are moved to the left, then box 1 floats to the left until it hits the containing box, and the other two boxes float to the left until it hits the previous floating box.

How to make CSS float

As shown in the figure below, if the containing box is too narrow to accommodate the three floating elements arranged horizontally, then the other floating blocks move downward until there is enough space. If floated elements are of different heights, they may get "stuck" by other floated elements as they move downward:

How to make CSS float

The above is the detailed content of How to make CSS float. For more information, please follow other related articles on the PHP Chinese website!

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