search
HomeWeb Front-endHTML TutorialXinxing completely helps you solve the floating problem in CSS_html/css_WEB-ITnose

Floating is a hurdle that must be passed in CSS layout. If you are not familiar with floating, then the layout of CSS is like a castle in the air. When it comes to floating, it is more combined with div, which is a block level Elements, I have introduced this in my previous blog post. If you like my style, you can search for it.

Now let’s get to the point. The so-called floating can be defined by the CSS attribute float. For example, float:left means floating to the left, and float:right means floating to the right. Let’s first look at an example of non-floating. The first is this html file. We will never touch this file. Its content is as follows:

	<link rel="stylesheet" type="text/css" href="my.css"><div id="demo1">区块1</div><div id="demo2">区块2</div><div id="demo3">区块3</div><div id="demo4">区块4</div>
Then we write its corresponding my.css file, the content is as follows :

#demo1{	background-color: #933;	height: 100px;width:300px;	 }#demo2{	background-color: #0F0;	height:60px;width:200px;}#demo3{	background-color: #F00;	height: 140px;width: 80px;}#demo4{	background-color: #CCC;	height: 80px;width: 180px;}
Then its interface at this time is as follows:

Next we make it in the second div Float right and add the following information, namely:

#demo2{	float: right;	background-color: #0F0;	height:60px;width:200px;}
I only gave the changes in demo2 above, and then we look at the following effect:

Let’s talk about what “ordinary flow” is. This may be a topic that may make novice friends particularly confused. The so-called ordinary flow is just like a book, laid out from top to bottom, left to right, normal HTML elements are all in the ordinary flow, and once an element floats, it is no longer in the ordinary flow. For example, if our block 2 floats right, it will look for the element above it. The previous element is block 1, and block 1 is an element in the ordinary stream, so block 2 is the same as block 1. The bottom is aligned. Ordinary flow determines its up and down position. Floating can only determine its left and right positions. Once the up and down positions are determined, the next step is its left and right positions. Since it is a right float, it is in right. Block three looks for its previous element and finds that its previous element is an element in the standard stream. Therefore, it will automatically align with the low end of block 1 and arrange downwards.

Someone may ask, what if block 2 floats to the left? We change the float attribute of demo2 to left, and we modify the width of block 3 to make it wider. Why don’t you explain? Clearly, the rendering is as follows:



I think the explanation in the above picture is relatively clear, so I won’t explain it in words. Someone may ask, what if the two blocks float together? Let’s first look at the situation of floating right:


Since the width here is wide enough, this layout can be completely accommodated, but what if we narrow the width? ? Look at the diagram below:


Actually, this is pretty easy to understand, so what if we continue to stretch to the left? The following situation will occur:


In fact, as long as the width is wide enough, block 3 is still to the left of block 2 instead of below it, but the width is too low. This is not the case. It reluctantly ran to the bottom of block 2, then started a new row and started arranging from the right.

In fact, the right float will be positioned, so the left float will be very clear. Its effect is as follows:


In fact, the same thing, if the space is too small , then block 3 will also be squeezed into a new line, as follows:



So, it can be summarized as Such a sentence: "The browser first arranges the blocks in the normal flow. They are very simple, just arrange them from top to bottom. For floating elements, it will check which of the nearest elements above it is in the normal flow. elements in it, and treat its bottom as its top, and then continue to arrange it according to the floating rules. Since the layout of the ordinary flow is carried out first, the floating elements will cover the elements in the ordinary flow. "

This section ends here. . . Let’s start with the floating ones again. . . .




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
利用CSS怎么创建渐变色边框?5种方法分享利用CSS怎么创建渐变色边框?5种方法分享Oct 13, 2021 am 10:19 AM

利用CSS怎么创建渐变色边框?下面本篇文章给大家分享CSS实现渐变色边框的5种方法,希望对大家有所帮助!

css ul标签怎么去掉圆点css ul标签怎么去掉圆点Apr 25, 2022 pm 05:55 PM

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

css与xml的区别是什么css与xml的区别是什么Apr 24, 2022 am 11:21 AM

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

css3怎么实现鼠标隐藏效果css3怎么实现鼠标隐藏效果Apr 27, 2022 pm 05:20 PM

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

css怎么设置i不是斜体css怎么设置i不是斜体Apr 20, 2022 am 10:36 AM

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

rtl在css是什么意思rtl在css是什么意思Apr 24, 2022 am 11:07 AM

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

css怎么实现英文小写转为大写css怎么实现英文小写转为大写Apr 25, 2022 pm 06:35 PM

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

怎么设置rotate在css3的旋转中心点怎么设置rotate在css3的旋转中心点Apr 24, 2022 am 10:50 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

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),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools