Home Web Front-end CSS Tutorial What is the positioning of css? Summary of css positioning

What is the positioning of css? Summary of css positioning

Aug 09, 2018 pm 04:36 PM
css positioning

This article brings you what is the positioning of css? The summary of CSS positioning has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Positioning is divided into:

static (default): This is The default value of the position attribute of page elements. The elements will be arranged according to the browser's arrangement rules for elements in the web page.

Note: Setting left, right, top, and bottom to the element at this time has no effect.

relative (relative positioning): Positioning relative to its original position! If position has not been set before or the position value is static, then after setting relative, the position of the element's left, right, top, and bottom will be moved with reference to its original position .

absolute (absolute positioning): Everyone should be familiar with this, that is, positioning that is separated from the document flow. The positioning reference object is its own parent, but its own parent must have the position attribute (it does not work if the parent's position attribute is static, it must be one of absolute, relative, and fixed). If its parent does not set the position attribute, it will look upwards for ancestor elements that have a position attribute and are not static, until the body element.

fixed (fixed positioning): This attribute is used to position the element relative to the browser window. No matter how you move your slider, it will be fixed. At a fixed position relative to the browser window, also note that its sibling elements will ignore its presence in positioning. The top, bottom, left, and right used at this time are also relative to the browser window.

Let me share my experience below:

1. Fixed will cause compatibility issues. The old IE6 does not support it. It is positioned relative to the browser!

2. The parent element has a position attribute (not static) and a padding value. If the child element only sets absolute, then

will not ignore the padding value of the parent element. If left: 0 is set , top:0 will ignore the padding value of the parent element.

3. Share the horizontal centering method of an element with absolute attribute:

Method 1: Normally we use left: 50%, and then margin-left: -width/2 To set the horizontal centering, I will share a method below. If you are asked about the horizontal centering method during the interview, you can add the following method, extra points!

Method 2: Set the child elements: left: 0, right: 0, and then set margin: 0 auto to center it horizontally.

4. Everyone should pay attention to what changes will occur when setting float and margin after setting position. This is very important and will be discussed with you later.

Related recommendations:

CSS3 animation properties: Introduction to the transform property

Code for implementing bubble boxes using pseudo elements in CSS3 ( before, after)

The above is the detailed content of What is the positioning of css? Summary of css positioning. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

See all articles