Summary of CSS sibling element floating analysis

Summary of CSS sibling element floating analysis

float:left/right/none;

1. Same level floating

(1) Make block-level elements appear in the same line (all elements to be displayed in the same line must be floated)

<div class="box1">box1</div>
<div class="box2">box2</div>
<div class="box3">box3</div>


.box1{
	border: 2px solid red;
	width: 40px;
	height:100px;
	float:left;
}
.box2{
	border: 6px solid black;
	width:100px;
	height:40px;
	float:left;
}
.box3{
	border: 12px solid blue;
	width:100px;
	height:300px;
	float:left;
} 

(2) Make inline elements support width and height

<span class="box1"></span>
.box1{
	border: 2px solid red;
	width: 40px;
	height:100px;
	float:left;
} 

3. When width or height is not set, the width and height are extended by the content;

<span class="box1">hello</span>

.box1{
	border: 2px solid red;
	float:left;
} 

4. If you add float to an element, it will be out of the standard document flow (document flow refers to the position of the object in the document) and will look for non-floating elements to cover it (floating backwards), and it will have nothing to do with the previous elements.

<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>


.box1{
	border: 1px solid red;
	width: 40px;
	height:100px;
	float:left;
}
.box2{
	border: 4px solid blue;
	width: 140px;
	height:40px;
	float:left;
}
.box3{
	border: 8px solid gray;
	width: 200px;
	height:200px;
	
} 

5. If an element is floated, it will first leave the standard flow and then float according to the floating direction until it hits the boundary of the previous floating element and stops, or falls down because the previous layer cannot accommodate the element and is placed on the next line;

<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>


.box1{
	border: 11px solid red;
	width: 40px;
	height:100px;
	float:right;
	
}
.box2{
	border: 4px solid blue;
	width: 140px;
	height:40px;
	float:left;
	
}
.box3{
	border: 8px solid gray;
	width: 200px;
	height:200px;
} 

6. When an element A floats on an element B that does not float, it will squeeze out the original position of B's ​​content, or even squeeze out

<div class="box1">box1</div>
<div class="box2">box2</div>
<div class="box3">box3</div>


.box1{
	border: 11px solid red;
	width: 40px;
	height:100px;
	
	
}
.box2{
	border: 4px solid blue;
	width: 60px;
	height:100px;
	float:left;
	
}
.box3{
	border: 8px solid gray;
	width: 200px;
	height:200px;
} 

When analyzing, if an element is floating, only look at the element in front of it. If the previous element is also floating, it will be displayed side by side. If the previous element is not floating, the relative position will remain unchanged.

Detailed analysis: https://www.jb51.net/web/76691.html

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Introduction and use of triggers and cursors in MySQL

>>:  HTML is something that web page creators must learn and master.

Recommend

mysql-5.7.28 installation tutorial in Linux

1. Download the Linux version from the official w...

Teach you how to build hive3.1.2 on Tencent Cloud

Environment Preparation Before starting any opera...

Detailed explanation of Vue two-way binding

Table of contents 1. Two-way binding 2. Will the ...

Docker installation and configuration command code examples

Docker installation Install dependency packages s...

Detailed explanation of Js class construction and inheritance cases

The definition and inheritance of classes in JS a...

Implementation process of row_number in MySQL

1. Background Generally, in a data warehouse envi...

jQuery implements navigation bar effect with expansion animation

I designed and customized a navigation bar with a...

How to set the memory size of Docker tomcat

When installing Tomcat in Docker, Tomcat may over...

Methods and steps for Etcd distributed deployment based on Docker

1. Environmental Preparation 1.1 Basic Environmen...

React implements import and export of Excel files

Table of contents Presentation Layer Business Lay...

Detailed tutorial on installing ElasticSearch 6.4.1 on CentOS7

1. Download the ElasticSearch 6.4.1 installation ...

How to install MySql in CentOS 8 and allow remote connections

Download and install. First check whether there i...