The introduction to floating is almost finished, here are some screenshots for reference
The following will introduce absolute positioning
Set to absolute positioning The element box is completely removed from the document flow and positioned relative to its containing block, which may be another element in the document or the initial containing block. The space previously occupied by the element in normal document flow is closed, as if the element did not exist. The element generates a block-level box after positioning, regardless of what type of box it originally generated in the normal flow.
Absolute positioning makes the position of the element independent of the document flow, so it does not occupy space. This is different from relative positioning, which is actually considered part of the normal flow positioning model because the element's position is relative to its position in the normal flow.
Let’s put aside the concept. Simply put
Absolute positioning means that margin and float are no longer needed for positioning, but positioning based on coordinates
Where is the starting point of the coordinates, it is the browser The point in the upper left corner
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } </style> <head> <body> <div id="a"> <div id="b"></div> </div> </body> </html>
But what happens if the parent div also defines absolute positioning or relative positioning?
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; position: absolute; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } </style> <head> <body> <div id="a"> <div id="b"></div> </div> </body> </html>
In other words, if an absolute definition is It makes no sense for a positioned layer to be contained by a non-absolute or relatively positioned layer. It is equivalent to a completely independent div and is not constrained by non-absolute or relatively positioned layers.
In fact, absolute positioning is better than absolute positioning Margin positioning is much more fun. Margin positioning needs to use the surrounding divs as reference objects, while absolute positioning only needs to adjust the coordinates according to the upper left corner.
Absolute positioning is separated from the text flow. It can go to any area, even that area. There is already a div occupying it
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; position: relative; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } #c{ width:100px; height:100px; border:soild; background:red; } </style> <head> <body> <div id="a"> <div id="c"></div> <div id="b"></div> </div> </body> </html>
So will it also cover the floating div?
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; position: relative; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } #c{ width:200px; height:200px; border:soild; background:red; float:left; margin:10px; } #d{ width:100px; height:100px; border:soild; background:blue; } </style> <head> <body> <div id="a"> <div id="c"></div> <div id="d"></div> <div id="b"></div> </div> </body> </html>
It can be seen that the absolutely positioned div is at the highest level and can cover all
That is to say, ordinary divs follow the flow pattern on the ground.
Floating divs follow the flow pattern in the air. One is an airplane on the ground and the other is an airplane in the air.
Then the absolutely positioned div is equivalent to an airship. It flies higher than an airplane and can move freely
Now let’s see what happens when two absolutely positioned divs meet together
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; position: relative; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } #c{ width:100px; height:100px; border:soild; background:red; position: absolute; left:60px; top: 20px; } </style> <head> <body> <div id="a"> <div id="c"></div> <div id="b"></div> </div> </body> </html>
They treat each other as if they do not exist, and do not care which area is occupied
Why is it green? Covering red, not red covering green?
Because here
Because the red div is in front, Green comes last, and the web page is parsed from top to bottom, left to right, so when the red div appears first, the green will cover it
In short, the farther back the absolutely positioned div is, the farther it flies. High, it can cover the previous absolutely positioned div
If you turn these two around, you will find that the red covers the green
Another way is to use the z-index attribute, The higher the z-index level, the higher it will fly. If not set, it will default to 0
<html> <head> <style type="text/css"> body{ margin:0; padding:0; } #a{ width:500px; height:500px; border:solid; margin-left:50px; position: relative; } #b{ width:100px; height:100px; border:soild; background:green; position: absolute; left:30px; top: 20px; } #c{ width:100px; height:100px; border:soild; background:red; position: absolute; left:60px; top: 20px; z-index:1; } </style> <head> <body> <div id="a"> <div id="c"></div> <div id="b"></div> </div> </body> </html>

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
