


css: position positioning attribute and summary of example applications
position positioning attribute
Position in css is a very important attribute. It includes absolute (absolute positioning), relative (relative positioning), static (static positioning, default value ), fixed (fixed positioning) four types. With the position property, we can offset an element relative to its normal position, its parent element, or the browser window. Position is also an attribute that beginners can easily get confused about. At present, almost all mainstream browsers support the position attribute. In the following article, we will talk about the position positioning attribute and its application in CSS.
You can first learn free courses related to php Chinese website
1. Study"HTML+CSS Basic Introduction Tutorial"中的CSS Basic Tutorial Positioning Chapter
2. Watch "Learn CSS Video Tutorial at Your Fingertips" 中CSS Positioning Video tutorial
##position positioning related applications
In-depth understanding of the position attribute in css
Absolute positioning will be completely taken out of the document flow, before the element The space occupied has also been recycled. Absolutely positioned elements are positioned based on their positioning context.It should be noted that: It is written here that absolute positioning can transform inline elements into block-level elements. But the certainty is that once an inline element is absolutely positioned, the position of the element is difficult to control (reason: if the element does not have inner and outer margins set, and there are no absolutely positioned elements before, after, left, and right, then the element will temporarily stay on its original position. position, but if the element has margins set, the element will temporarily stay one margin away from the original position. If there are elements with absolute positioning set on the front, back, left, and right, then the element will look for the top one that is not. Below the absolutely positioned element.
The difference between relative and absolute in parsing css position
position has the following attributes: static, inherit, fixed, absolute, relativeThe first three Easy to understand and distinguish:
static: It is the default state, there is no positioning, and the element appears in the normal flow (ignoring top, bottom, left, right or z-index statements).
nherit: Inherit the value of the position attribute from the parent element.
fixed: Generate absolutely positioned elements, positioned relative to the browser window. (That is, when scrolling the browser, the element is always displayed at a certain position in the visible area of the window).
Introduction to the use of CSS positioning
absolute and fixedFeatures:
a. The width of block-level elements is When undefined, it is no longer 100%, but is automatically adjusted according to the contentb. When z-index is not defined, the absoulte element will cover other elements. c. It will break away from the normal document flow and no longer occupy space, similar to the effect after floating. absolute is an absolute positioning relative to the previous parent element that is not static. If the position of the parent element is not specified, absolute will be positioned absolutely relative to the entire HTML document. 4.Instructions for positioning methods using the position attribute in CSS
Summary of the four methods of positioning in css
Departing from the standard document flowFeatures: (1) If this element has no parent element, then top, left, right, and bottom will be positioned relative to the browser window in the future
(2) If the absolutely positioned element has a parent element , but the parent element is not relatively positioned, then at this time top, left, right, and bottom are still positioned relative to the browsing window
(3) If the absolutely positioned element has a parent element, and the parent element is positioned ( Non-static), then the offset of this absolutely positioned element is based on its own parent element
(4) The element after absolute positioning will not occupy the position on the page
a. If there is a p with a default width of 100%, once absolute positioning is added, the element will be inline-blocked immediately, and the default width will automatically Adapting to the internal width of the element will cause the width and height of the page to collapse.
b. Due to the flexibility of absolute positioning, for ordinary page layouts, sometimes it is easy to abuse absolute/relative/top/left/z-index for the sake of saving trouble, which will cause later Expansion and maintenance cause trouble
Related questions and answers
1. How to achieve similar functions without using position:absolute
2. Mobile side position:fixed; compatibility issues
3. css part position fixed web page problem Drop-down made of pure css
4. How can a div move left and right with the browser after setting the position: fixed attribute?
【Related recommendations】
1. PHP Chinese website free tutorial: 《CSS 0 Basics Introduction Tutorial》
2. PHP Chinese Free online video tutorial: "php.cn Dugu Jiujian (2) - css video tutorial"
The above is the detailed content of css: position positioning attribute and summary of example applications. For more information, please follow other related articles on the PHP Chinese 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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

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

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
