Floating is not new to CSS3. The float attribute can be used to define the direction in which the element floats. This attribute has been available in CSS1; no matter what element is set to float, after setting the float, the element will generate a block-level box, and the syntax is "element {float :value;}".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
float attribute defines in which direction an element floats. Historically this property has always been applied to images, causing the text to wrap around the image, but in CSS, any element can be floated. A floated element creates a block-level box, regardless of what type of element it is.
If floating non-replaced elements, specify an explicit width; otherwise, they are made as narrow as possible.
Note: If there is very little space for a floating element on a row, the element will jump to the next row, and this process will continue until a certain row has enough space.
The horizontal floating direction of the element means that the element can only move left and right but not up and down.
A floating element will try to move left or right until its outer edge touches the border of the containing box or another floating box.
Elements after the floated element will surround it.
Elements before the floated element will not be affected.
If the image is right-floated, the following text flow will wrap to the left of it:
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123/title> <style> img { float:right; } </style> </head> <body> <p>在下面的段落中,我们添加了一个 <b>float:right</b> 的图片。导致图片将会浮动在段落的右边。</p> <p> <img src="logocss.gif" style="max-width:90%" style="max-width:90%" / alt="Is float new to css3?" > 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 这是一些文本。这是一些文本。这是一些文本。 </p> </body> </html>
Output result:
(Learning video sharing: css video tutorial)
The above is the detailed content of Is float new to css3?. For more information, please follow other related articles on the PHP Chinese website!