Home>Article>Web Front-end> How to make an element exceed its parent element in css

How to make an element exceed its parent element in css

藏色散人
藏色散人 Original
2021-04-13 10:22:27 6164browse

How to implement CSS to make elements exceed the parent element: 1. Set the positioning of the parent container to "relative", which means relative positioning; 2. Set the positioning of the child container to "absolute", which means absolute positioning.

How to make an element exceed its parent element in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

CSS makes the child container exceed the parent element (the child container is suspended in the parent container)

Preface

Sometimes, we need a suspension effect as shown below:
How to make an element exceed its parent element in css
How to make an element exceed its parent element in css

Achieve

in standard normal situations This can only be done usingabsolute positioning.
How to make an element exceed its parent element in css

Step one: Set the parent container positioning torelative (relative positioning).
Step 2: Set the subcontainer positioning toabsolute (absolute positioning).

我要浮出去!

#a{ width:400px; height:100px; background:rgb(0, 0, 0); position:relative;/*父元素>相对定位*/}#b{ width: 150px; height:50px; background:rgb(185, 155, 255); position:absolute;/*子元素>绝对定位*/ top:-30px;/*控制浮出*/ /* left:XX; */}

Rendering:
How to make an element exceed its parent element in css

[Recommended learning:css video tutorial]
Parent element settingsAbsolute positioning, the child element is set torelative positioning, that is, the child element is positioned according to the parent element.

Note: Only child elements will break away from the document flow. The parent element is relatively positioned and will not break away from the document flow, so it will not cause page dislocation.

The above is the detailed content of How to make an element exceed its parent element in css. 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