This time I will bring you the positioning in H5, what are the precautions for positioning in H5, the following is a practical case, let's take a look.
1. Positioning flow classification
1.1 Relative positioning
1.2Absolute positioning
1.3Fixed positioning
1.4Static positioning
2. What is relative positioning?
Relative positioning is to move relative to its previous position in the standard stream
position: relative;
Notes on relative positioning
1. Relative positioning does not break away from the standard flow and will continue to occupy a space in the standard flow.
2. In relative positioning, only one can be used for the positioning attribute in the same direction (that is, use If you use left, don’t use right; if you use top, don’t use bottom).
3. Since relative positioning does not deviate from the standard flow, block-level elements/inline elements are distinguished in relative positioning. Element/inline block-level element
4. Since relative positioning does not deviate from the standard flow, and relatively positioned elements will occupy positions in the standard flow, when setting attributes such as margin/padding for relatively positioned elements, it will Affects the layout of the standard flow,(margin/padding will be added to the box position before positioning)
Relative positioning application scenario
1. Used for Fine-tune the elements
2. Use it in conjunction with the absolute positioning you will learn later
.box2{ background-color: green; position: relative; //相对定位 top: 20px; left: 20px; margin-top: 20px;//会加在定位之前的位置上 }
3. What is absolute positioning?
Absolute positioning is positioning relative to the body
position: absolute ;
Notes
1Absolutely positioned elements are out of standard flow
2Absolutely positioned elements do not distinguish between block-level elements/inline elements/inline block-level elements
.box2{ background-color: green; position: absolute; //绝对定位 left: 0; bottom: 0; //在body的左下角 }
4. Absolute positioning reference point
Rule
1. By default, all absolutely positioned elements, regardless of whether they have ancestor elements or not, will use the body as the reference point
2. If an absolutely positioned element has an ancestor element, and the ancestor element is also a positioning stream, then the absolutely positioned element will use the ancestor element of the positioning stream as a reference point
2.1 As long as this The ancestor elements of absolutely positioned elements can all be used
2.2 The positioning flow refers to absolute positioning/relative positioning/fixed positioning
2.3 Only static positioning in the positioning flow will not work
3 .If an absolutely positioned element has an ancestor element, and the ancestor element is also a positioning flow, and there are multiple elements in the ancestor element that are positioning flows, then the absolutely positioned element will be based on the ancestor element of the positioning flow closest to it. Reference points
5. Note points
1. If an absolutely positioned element uses the body as the reference point, then it actually uses the width and height of the first screen of the web page as the reference point, not Use the width and height of the entire web page as a reference point;
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
The layout method of web pages: clearing floats
The above is the detailed content of Positioning in H5. For more information, please follow other related articles on the PHP Chinese website!

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...


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

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

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.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
