A brief analysis of the usage of HTML float

A brief analysis of the usage of HTML float

Some usage of float

Left suspension: float:left;
Right suspension: float:right;

Float usage

Float has a wide range of uses. Here is a brief introduction to its most common uses:

  • Before I came across float, I would set some inline-block and block attributes with div inlay to complete the layout of the page. Then I came across the float attribute, which made it much easier to float the elements directly. There is no distinction between block-level elements, inline elements, or inline-block elements in the float. Float will also automatically layout as the parent element width changes, e.g. directly adjusting the visible window will squeeze the element to the next line.
  • In addition, as far as the SEO optimization we just learned is concerned, since the browser parses from top to bottom, most of the time the important content is written in the front, and some unimportant or advertisements are written in the back. However, we also want users to notice the advertisements, so most of the time the main content is arranged in the center, and the advertisements are suspended on the left and right. I believe that friends who often browse the web have also noticed this. Next, let’s talk about some of the writing and effects of suspension.

If a child element is suspended, the height of the parent element will collapse. This involves clearing the suspension, which will be explained in the next chapter.
So let's get back to the point,

The first phenomenon is float=inline-block

When suspended, the four blocks will be displayed in inline block mode: as shown below

<style>
        div{
            width:200px;
            height:200px;
            background-color: pink;
            border:1px solid black;
            float:left;
        }
    </style>
<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</body> 

The second phenomenon:

As shown in the figure below, since the first block element is floating, the second block element will be displayed below the first one.
But when the next element is suspended, it will not go over the previous element. For example, the fourth block element is suspended, but the third one is not. The fourth block element remains in its original position.

 <style>
        .first-one{
            float:left;
            background-color:green;
        }
        .second-one{
            background-color:purple;
        } 
        .third-one{
           
            background-color:blue;
        } 
        .fourth-one{
            float:left;
            background-color:grey;
        } 
        div{
            width:200px;
            height:200px;
            background-color: pink;
            border:1px solid black;
            font-size:30px;
        }
    </style>
<body>
    <div class="first-one"></div>
    <div class="second-one"></div>
    <div class="third-one"></div>
    <div class="fourth-one"></div>
</body> 

The third phenomenon:

If all elements are floated, and the remaining width of the parent element is not enough to support the child elements in the row, then they will be aligned to the upper level.

This article is transferred from: https://segmentfault.com/a/1190000022669455

Summarize

This is the end of this article about the usage of HTML float. For more relevant HTML float content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of JavaScript's Set data structure

>>:  MySQL index principle and query optimization detailed explanation

Recommend

Summary of Problems in Installation and Usage of MySQL 5.7.19 Winx64 ZIP Archive

Today I learned to install MySQL, and some proble...

Detailed explanation of Nginx http resource request limit (three methods)

Prerequisite: nginx needs to have the ngx_http_li...

SQL implementation of LeetCode (178. Score ranking)

[LeetCode] 178.Rank Scores Write a SQL query to r...

How to upload and download files between Linux server and Windows system

Background: Linux server file upload and download...

Sharing tips on using vue element and nuxt

1. Element time selection submission format conve...

JavaScript to achieve fancy carousel effect

This article shares two methods of implementing t...

Nginx stream configuration proxy (Nginx TCP/UDP load balancing)

Prelude We all know that nginx is an excellent re...

How to install git on linux

1. Introduction Git is a free, open source distri...

Analysis of the principle of Vue nextTick

Table of contents Event Loop miscroTask (microtas...

Analyze the method of prometheus+grafana monitoring nginx

Table of contents 1. Download 2. Install nginx an...

Summary of Docker Data Storage

Before reading this article, I hope you have a ba...

How to reasonably use the redundant fields of the database

privot is the intermediate table of many-to-many ...

Practical method of upgrading PHP to 5.6 in Linux

1: Check the PHP version after entering the termi...