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

How to make the box float in css

王林
Release: 2020-11-17 16:30:45
Original
6710 people have browsed it

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;
Copy after login

You can use clear to clear floats:

clear: left | right | both;
Copy after login

Float(float)

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

Syntax: selector { float: attribute value; }

left:元素向左浮动
right:元素向右浮动
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template