Three ways of html+css layout (natural layout/flow layout/positioning layout)

Three ways of html+css layout (natural layout/flow layout/positioning layout)
1. Natural layout <br />The layout without any modification is automatically aligned to the left.
2. Fluid layout <br />The situation of float:left mentioned above.
3. Positioning layout <br />Relative positioning and absolute positioning are both relative to the parent div tag.
Relative - Use the original position of the element as the reference point. Absolute - Use the origin (upper left corner) of the parent div tag as the reference point.

Since the outer layer is position:relative, if the inner layer is absolute, it will be aligned with the upper left corner of the outer layer as the displacement reference. Of course, the outer layer only writes position:relative, and writes the two values ​​​​left and top, which means: the position where this element should be originally located is used as the layout reference origin for left and top alignment.

There is another situation where there is only one position:absolute; there is no position:relative on the outer layer. Which point will be used as a reference at this time? The principle at this time is: if there is a relative element in a parent element, the parent element is used as the reference origin; if there is no position:relative, the body is used as the reference origin. If there is no relative outer layer of position:absolute, there is no difference between the two layouts.

Of course, the last case is: the outer layer is: position: absolute; the inner layer is position: relative, what will happen then? According to the original principle, absolute will refer to the body as the layout origin, and relative will refer to the position where it should be as the layout origin. At this time, it actually refers to the upper left corner of the outer layer as the layout origin.
The rest depends on the actual situation.

<<:  Detailed explanation of how to pass values ​​between react hooks components (using ts)

>>:  How to choose transaction isolation level in MySQL project

Recommend

Solve the mysql user deletion bug

When the author was using MySQL to add a user, he...

Why is it not recommended to use an empty string as a className in Vue?

Table of contents Compare the empty string '&...

Summary of Vue3 combined with TypeScript project development practice

Table of contents Overview 1. Compositon API 1. W...

Tutorial on installing MySQL database and using Navicat for MySQL

MySQL is a relational database management system ...

Detailed analysis of Vue child components and parent components

Table of contents 1. Parent components and child ...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

How to use Maxwell to synchronize MySQL data in real time

Table of contents About Maxwell Configuration and...

Detailed explanation of the use of umask under Linux

I recently started learning Linux. After reading ...

Several methods of calling js in a are sorted out and recommended for use

We often use click events in the a tag: 1. a href=...

CSS Tutorial: CSS Attribute Media Type

One of the most important features of a style she...

Use of Linux usermod command

1. Command Introduction The usermod (user modify)...

Realization of real-time file synchronization between Linux servers

Usage scenarios For existing servers A and B, if ...

js implementation of verification code case

This article example shares the specific code of ...