Home  >  Article  >  Web Front-end  >  How to make the box float in css

How to make the box float in css

王林
王林Original
2020-11-11 10:29:206687browse

How to make the box float in css: You can use the float attribute, such as [float: left;]. The float attribute allows multiple boxes to be arranged horizontally in a row, left or right. The width of the box is no longer stretched, but is determined based on the width of the content inside the box.

How to make the box float in css

Box float

In standard flow, a block-level element will automatically stretch horizontally until the edge of the element containing it connected; and arranged in sequence with adjacent elements in the vertical direction, not side by side.

(Learning video recommendation: java video tutorial)

The float attribute in CSS defaults to none. Setting the value of the float attribute to left or right will move the element to the left or right of its parent element. At the same time, by default, the width of the box no longer stretches, but is determined based on the width of the content inside the box.

float: left;

You can use clear to clear floats:

clear: left | right | both;

Float(float)

Function: Arrange multiple boxes horizontally in a row, left and right

Syntax: selector { float: attribute value; }

left:元素向左浮动
right:元素向右浮动

Features:

will float on top of the standard stream

The display will not occupy the position of the standard stream box

will be converted to an element similar to an inline block, but there will be no gaps between elements

Related recommendations: CSS tutorial

The above is the detailed content of How to make the box float in css. 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