Home  >  Article  >  Web Front-end  >  Introduction to relative positioning and absolute positioning in CSS

Introduction to relative positioning and absolute positioning in CSS

黄舟
黄舟Original
2017-05-27 13:53:191417browse

1. Generally, if we do not set position for an element, the default is static. At this time, the element is not positioned, and offset attributes such as left/right have no effect.

2.position:relative (relative positioning)

If set to relative positioning, you can configure the left/right offsets relative to the original position of the element , and the original position still occupies the space of the document flow, and the offset will not crowd out other elements, So if overlap occurs, the stacking order can be set through z-index.

3.position:absolute

When an element is set to absolute positioning, it does not occupy space in the document flow and will float. Different from relative positioning, absolute positioning will delete the space of the original position in the document flow. Positioning is positioned through the parent element that is not static. (If the parent element is static, then find the parent element of the parent element. Element, go to the upper level to find).

The above is the detailed content of Introduction to relative positioning and absolute positioning 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