This article introduces to you the content of the article about the position attribute value in HTML. It has a good reference value. I hope it can help friends in need.
Theoretically, there are 8 values for all positions
Including: position: static | relative | absolute | fixed | sticky | initial | inherit | unset
The most commonly used ones are static, relative, absolute, fixed and sticky
initial, inherit and unset are css Keywords, any css attribute value can be set to these values
position: static
Default value, in normal flow, the set top, left, right, bottom, z-index should be ignored
position: relative
Relative positioning, Offset relative to its original position, (Example: top: 10px; // After moving, the top of the element is located 10px below the top of the original position;)
Detach from the document flow, but retain the space at the original position in the document flow (Reserved space),
That is to say , the original position of the element will always remain a blank space, and the adjacent sibling elements will maintain their original position and will not change with the movement of the element
Note: position: relative to table-* -The group, table-row, table-column, table-cell, table-caption elements are invalid.
Chestnut:
##position: absolute
Absolute positioning, if the ancestor element has an attribute value other than position: static, thenAbsolute positioning is relative to the ancestor element; otherwise, Absolute positioning is relative to the browser viewport
(One thing to note here is that most people think that it is absolutely positioned relative to the html or body element. This is a misunderstanding; when the page is scrollable, it can be seen that it is absolutely positioned relative to the browser window. Instead of the entire html content; I am too lazy to write examples here, so I will just learn from others:CSS Advanced - How to define the width and height of absolutely positioned elements)
Therefore, the general approach is to add the position: relativeattribute to the parent element of the absolutely positioned element
out of the document flow without reserving space. Move the position of sibling elements upChestnut:specify top / bottom / left / right, leaving height unspecified (i.e. auto), to fill the available vertical (horizontal) space
What does it mean? Calm down, let’s eat some chestnuts: (In addition,absolutely positioned elements can be set with margins , and will not be merged with other margins, this will not Give me an example)
question:
Since absolute positioning is detached The document is flowing. Why is the origin of an inline element located at its original position when the left value is not set when it is absolutely positioned? Instead of being at the origin of the parent element?
(I haven’t found the reason for a long time, I’ll leave this for later)position: fixed
Fixed positioning,Fixed positioning relative to the browser window, not scrolling with the scroll bar, the sample implemented is the advertising pop-up window in daily web pages
out of the document The stream, fixed attribute creates a new cascading context.Note: When the transform attribute of the ancestor element of the fixed element is not none, the container is changed from the browser window to the ancestor element
position: sticky
Sticky positioning is equivalent to a mixture of relative positioning and fixed positioning. Sticky positioning is determined based on a threshold. When it is greater than or equal to the threshold, relative positioning is used, and when it is less than the threshold, it is fixed positioning.
This threshold is one of top, right, bottom, and left. One of them must be set for sticky positioning to take effect, otherwise it will always appear as relative positioning.
In addition to the above conditions, there are several points that need to be paid attention to, otherwise sticky positioning will be invalid:
1. The parent element The content needs to be scrolled and cannot have overflow: hidden or overflow: auto attributes
2. The height of the parent element cannot be lower than the height of the sticky positioning element
3. Sticky is container-related and will only take effect in the container (parent element) in which it is located.
sticky Chestnut:demo
Sticky positioningCompatibilityQuestions:
1. Need to write The next two css statements:
position: sticky; and position: -webkit-sticky; /* Safari */
2. Internet Explorer, Edge 15 and above Earlier IE versions did not support sticky positioning.
position: initial
The initial keyword is used to set the CSS property to its default value (in this case, position: static)
Note: IE does not support this keyword
position: inherit
Every The overview of each CSS property definition indicates whether the property is inherited by default ("Inherited: Yes") or not inherited by default ("Inherited: no").
You can read about the wonderful use of inherit here: Talk about some interesting CSS topics (4) – Starting with reflection, talk about CSS inheritance
position: unset
The unset keyword is a combination of initial and inherit:
1. If the attribute is If the attribute is inherited by default, the value is equal to inherit
2. If the attribute is a non-inherited attribute, the value is equal to initial
Related recommendations:
Summary of different table attributes of HTML (with code)
HTML imitation of Baidu homepageThe above is the detailed content of Introduction to the position attribute value in HTML. For more information, please follow other related articles on the PHP Chinese website!

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment