In the process of learning CSS, we often see css float and css clear float. So, what does css float mean? Why does css need to clear floats? This article will introduce to you the meaning of CSS floating and the reasons why CSS clears floating.
1. First, let’s take a look at what does CSS floating mean?
We can know from Baidu Encyclopedia: float is the positioning attribute in css style, used to set label objects (such as:
In CSS, we realize the floating of elements through the float attribute. (For more information on float attributes, please refer to css manual)
The meaning mentioned above seems to come and go, so let’s explain it in a layman’s terms below.
You must know that some elements in css are block-level elements, and they will automatically enable a new line (block-level element reference article: What is the definition of css block-level elements? What are the css block-level elements? ?), there is another type of inline elements, which are inline elements. They will remain displayed in "one line" with the previous content (inline elements reference article: What are the css inline elements? css block-level elements The difference from inline elements); but sometimes we need to change this layout method, which requires using CSS floating.
CSS floats allow a given element to move to one side of its row and allow other content to flow downward. A right-floated element will be pushed to the right side of its container, and content will flow down its left side. An element with a float will be pushed to the left, and its content will flow down its right side. flow down.
After reading the meaning of CSS floating, let’s take a look at why CSS needs to clear floating?
2. Why does CSS need to clear floats?
After the above explanation of what css floating means, we know that css floating must exist in some cases, so why should we clear the floating?
We need to know: a floating box can move left and right until it encounters another floating box or a containing box on its outer edge. The floating box does not belong to the ordinary flow in the document flow. When the element is floated, it will not affect the layout of block-level elements, but will only affect the layout of inline elements. At this time, the normal flow in the document flow will show that the floating box does not have the same layout mode. When the height of the containing box is smaller than the floating box, "height collapse" will occur. At this time, it is necessary to clear the float.
To put it simply:
For example: if the float is not cleared, the problem of div overlap will occur. You make a web page with a header block at the top, two columns of content blocks in the middle, and a footer block at the bottom. You set a left float in the middle content block, and the heights of the two blocks are inconsistent. If one block is higher, then the float needs to be cleared in the footer. If the float is not cleared, the footer block will overlap with one of the contents, such as Picture:
Related recommendations:
The above is the detailed content of What does css float mean? Why does css need to clear floats?. For more information, please follow other related articles on the PHP Chinese website!

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
