Home > Web Front-end > CSS Tutorial > How do css elements overlap?

How do css elements overlap?

青灯夜游
Release: 2020-11-30 13:32:29
Original
6057 people have browsed it

How to overlap css elements: 1. Set negative margin to the element. Negative margin can make the element take up less space, and subsequent elements can cover the current element; 2. Use the position attribute, using relative positioning and Absolute positioning to allow multiple elements to overlap.

How do css elements overlap?

The operating environment of this tutorial: Windows 10 system, CSS3 version. This method is suitable for all brands of computers.

How CSS elements overlap:

Method 1. Set negative margin

to the element Set negative margin so that the original position will not be retained after moving

Negative margin can make the element take up less space. Later elements can cover the current element

(There are two here The width and height of p's of the same size are 100px (Figure 1). When we set -margin-bottom to the p with the class name p above (see Figure 2), we found that the following elements covered the position of -margin)

Figure 1:

这里有两个相同大小的p 宽高都是100px
How do css elements overlap?

Method 2. Use positioning

Relative positioning (position: relative): the original position is retained and will not squeeze into other elements, but will only overlap

Absolute positioning (position: absolute): the original position will not be retained and will break away from the page flow

Example:

How do css elements overlap?

Effect:

How do css elements overlap?

For more programming-related knowledge, please visit: Programming Learning Website! !

The above is the detailed content of How do css elements overlap?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template