search
HomeWeb Front-endCSS TutorialDetailed explanation of positioning attribute position: relative and absolute

Positioning tag: position

Contains attributes: relative(relative)

                                                                                                                                               

position:relative; If an element is positioned relatively, first it will appear at its location. Then move the element "relative to" its original starting point by setting a vertical or horizontal position. (One more point, when relative positioning, the element still occupies the original space regardless of whether it is moved. Therefore, moving the element will cause it to cover other boxes)

Relative positioning: relative does not break away from the normal document flow and is set The element is positioned relative to its original position, and its original placeholder information still exists

2.position:absolute; means

absolute positioning, and the position will be calculated based on the upper left corner of the browser. Absolute positioning takes the element out of the document flow so it doesn't take up space. Elements in normal document flow are laid out as if absolutely positioned elements were not present. (Because absolutely positioned boxes have nothing to do with document flow, they can cover other elements on the page and their hierarchical order can be controlled via z-index. The higher the z-index value, the more visible it is. At the upper level.)

Absolute positioning: ablution is separated from the document flow and

floating model, and exists independently of other objects, without placeholders.

3. After the parent container uses relative positioning and the child element uses absolute positioning, the position of the child element is no longer relative to the upper left corner of the browser, but relative to the upper left corner of the parent window

Specific case description:

1. If c is nested in b, and b and c are both relatively positioned, then the relative positioning of c is relative to b, b retains the placeholder information, and b retains the placeholder information of c.

2. If c is nested in b, b is positioned absolutely, and c is positioned relatively, then b is out of float and has no placeholder information, while c is positioned relative to b, and placeholder occurs in b.

3. If a, b, c, d are juxtaposed and are all nested in a div with the id of group, and:

#group{potision:relative;height
:200px;width:4oopx ;}      #b{potision:absolute;left:20px;top:20px;}
In this way, the parent element is relatively positioned, but the values ​​of left and top are not set. It can be regarded as Floating object, and b is absolutely positioned, so it does not occupy space. However, since the parent element is relatively positioned, the absolute positioning here becomes absolute positioning relative to the parent element, not relative to the browser.

For example:

<div id="main">
<div id="a">aaaaaaaaaa</div>
<div id="b">bbbbbbbb</div>
</div>

(1) If position: absolute is set to a, a will be separated from the normal document flow, and a will not occupy a position, that is, b is no longer based on a, but directly from parent Start positioning. (The b position is the same as without a).


If position:relative is set for a, (without breaking away from the document flow), a will occupy the position. A is positioned relative to its original position, and it appears to be floating on main, while b It will be arranged in the original way and will not be affected by a. (The position of b is the same as when a has no position attribute)
(2) If position is set to main: relative/absolute; then the absolute positioning or relative positioning of a or b inside is relative to the parent element main. Then position according to the relative or absolute method

Note: If the parent element does not set a valid width and height value, b is absolutely positioned relative to the upper right corner of the last element in the group. The parent element needs to be set. Width Height! ! ! ! ! ! ###

The above is the detailed content of Detailed explanation of positioning attribute position: relative and absolute. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
解决Go语言开发中的内存泄漏定位问题的方法解决Go语言开发中的内存泄漏定位问题的方法Jul 01, 2023 pm 12:33 PM

解决Go语言开发中的内存泄漏定位问题的方法内存泄漏是程序开发中常见的问题之一。在Go语言开发中,由于其自动垃圾回收机制的存在,内存泄漏问题相对其他语言来说可能较少。然而,当我们面对大型复杂的应用程序时,仍然可能会出现内存泄漏的情况。本文将介绍一些在Go语言开发中定位和解决内存泄漏问题的常用方法。首先,我们需要了解什么是内存泄漏。简单来说,内存泄漏指的是程序中

H5中position属性的灵活运用技巧H5中position属性的灵活运用技巧Dec 27, 2023 pm 01:05 PM

H5中如何灵活运用position属性在H5开发中,经常会涉及到元素的定位和布局问题。这时候,CSS的position属性就会发挥作用。position属性可以控制元素在页面中的定位方式,包括相对定位(relative)、绝对定位(absolute)、固定定位(fixed)和粘附定位(sticky)。本文将详细介绍在H5开发中如何灵活运用position属性

CSS 布局属性优化技巧:position sticky 和 flexboxCSS 布局属性优化技巧:position sticky 和 flexboxOct 20, 2023 pm 03:15 PM

CSS布局属性优化技巧:positionsticky和flexbox在网页开发中,布局是一个非常重要的方面。良好的布局结构可以提高用户体验,使页面更加美观和易于导航。而CSS布局属性则是实现这一目标的关键。在本文中,我将介绍两种常用的CSS布局属性优化技巧:positionsticky和flexbox,并提供具体的代码示例。一、positions

h5如何使用positionh5如何使用positionDec 26, 2023 pm 01:39 PM

在H5中使用position属性可以通过CSS来控制元素的定位方式:1、相对定位relative,语法为“style="position: relative;”;2、绝对定位absolute,语法为“style="position: absolute;”;3、固定定位fixed,语法为“style="position: fixed;”等等。

html怎样把div放在底部html怎样把div放在底部Mar 02, 2021 pm 05:44 PM

html把div放在底部的方法:1、使用position属性将div标签相对于浏览器窗口进行定位,语法“div{position:fixed;}”;2、设置到底部距离为0来把div永远放置于页面底部,语法“div{bottom:0;}”。

怎样发位置给别人怎样发位置给别人Jun 27, 2023 am 10:13 AM

发位置给别人的方法是:1、使用手机地图发位置,分享界面上选择合适的通讯应用或者社交媒体,将位置信息发送给需要的人;2、使用第三方位置分享工具,实现设备之间的位置共享;3、利用Wi-Fi,蓝牙和Beacon技术发位置。

position有哪些属性position有哪些属性Oct 10, 2023 am 11:18 AM

position属性取值有static、relative、absolute、fixed和sticky等。详细介绍:1、static是position属性的默认值,表示元素按照正常的文档流进行布局,不进行特殊的定位,元素的位置由其在HTML文档中的先后顺序决定,无法通过top、right、bottom和left属性进行调整;2、relative是相对定位等等。

如何在uniapp中实现百度地图定位如何在uniapp中实现百度地图定位Jul 04, 2023 pm 12:07 PM

如何在UniApp中实现百度地图定位引言:UniApp是一款基于Vue.js的开发框架,可以用于快速开发跨平台的应用程序。在今天的数字化时代,地图定位功能已经成为许多应用程序的重要组成部分。本文将教您如何在UniApp中使用百度地图定位功能,并提供相应的代码示例。一、准备工作在开始之前,我们需要进行一些准备工作。首先,您需要在百度开发者平台注册一个开发者账号

See all articles

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment