


Detailed explanation of positioning and positioning application of div css
Extended reading
* Interpretation of absolute and relative a>
* position: relative/absolute level that cannot be broken
* Supplement to the article "Unbreakable Levels"
Positioning has always been a difficult point in the application of WEB standards. If the positioning is not clear, the effect that should be achieved may not be achieved, and the achieved effect may be distorted. If the principle of positioning is clarified, positioning will make the web page more perfect.
Definition of positioning:
The content about positioning in CSS is :position:relative | absolute | static | fixed
static There is no special setting, it follows the basic positioning regulations and cannot be hierarchical through z-index.
relative does not break away from the document flow, refers to its own static position through top, bottom, left, right positioning, and can be hierarchical through z-index.
Absolute is separated from the document flow and positioned through top, bottom, left, and right. Select its nearest parent positioning element. When the parent position is static, the absolute element will be positioned at the origin of the body coordinates and can be hierarchically graded through z-index.
fixed fixed positioning, here the fixed object is the visual window rather than the body or parent element. Hierarchical classification can be done through z-index.
Cascading grading of positioning in CSS: z-index: auto | namber;
auto follows the positioning of its parent object
namber A unitless integer value. Can be negative
Principle of positioning:
Elements that can be displaced (relative positioning)
In the text flow, any element has its own position limited by the text flow, but through CSS we still make these Elements can change their position. We can use float to float the element, and we can also use margin to move the element's position. But in fact, that is not the real displacement, because it is just a deception achieved by increasing the margin value. The displacement in the real sense is generated by top, right, bottom, left (hereinafter referred to as TRBL, TRBL can be divided into two parts) for a relatively positioned element.
And we note that the coordinate point of the positioned element is at the upper left edge point of the margin value, which is point B in the figure. Then all displacement calculations will be based on this point to push the element. The direction of displacement is cohesive when TRBL is positive. It can be deduced that when TRBL is negative, the direction of displacement is outward. In the picture, there is a displacement arrow pointing to the mark. The plus sign indicates the positive displacement direction, and the minus sign indicates the negative displacement direction. Regarding the displacement direction, you can further read Yi Fei's "Talk about the margin attribute from the simple to the deep (1)"
Elements that can be in any position (absolute positioning)
As mentioned above: Relative positioning can only move the position up, down, left, and right in the text flow. It also has certain limitations. Although its presentation area is separated from the text flow, it is still retained in the text flow. A place is like a migrant worker who goes to another place, but still has a place exclusive to him in his hometown, and this place does not change with his movement. But this will obviously leave a blank space. If you want the text flow to abandon this part, you need to use absolute positioning. Absolute positioning not only breaks away from the text flow, but also does not leave an exclusive space for this absolutely positioned element in the text flow. This is like a position in a factory. If one worker leaves, other workers will naturally fill the position. The part that moves out naturally becomes a free body. Absolute positioning will set the element to any position through TRBL. When the position property of the parent layer is the default value, the coordinate origin of TRBL starts from the coordinate origin of the body.
Associated absolute positioning
The above is a single absolute positioning, but in actual applications we often A special form will be required. That is, you want the positioned element to have absolute positioning characteristics, but you also hope that the coordinate origin of the absolute positioning can be fixed at a certain point in the web page. When this point is moved, the absolutely positioned element can ensure its relative position relative to the original coordinates. That is to say, this absolute positioning needs to move with the web page and be fixed at a fixed position on the web page. Usually this effect is particularly important when the web page is centered. The basic way to achieve this effect is to set the absolutely positioned parent to relative positioning or absolute positioning. Then the coordinates of absolute positioning will take the parent as the starting point of the coordinates.
Although this is the case, the coordinate origin is not the parent coordinate origin. This is a very strange coordinate position.
Elements that are always in sight (fixed positioning)
Due to the abuse of advertising, some browser software has begun With ad content blocking, some great effects are no longer recommended. For example, an element may continuously change its position as the web page scrolls. Now I can achieve such an effect through a positioning attribute in CSS. This element attribute is position:fixed, which was not supported in the past; its meaning is: fixed positioning. This fixing is very similar to absolute positioning. The only difference is that absolute positioning is fixed at a certain position in the web page, while fixed positioning is fixed at the browser's view frame position.
Although the original browser did not support this attribute, the development of browsers has enabled today's advanced browsers to correctly parse this CSS attribute. And through CSS HACK, IE6 can achieve this effect (currently IE5.x cannot achieve this effect). In order not to make this article become a long article, only this example is given here to end this article. You can analyze some issues about this example by yourself. If you don’t understand something, please leave me a message!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool