The position attribute in CSS is used to define the position of elements in the document flow. The possible values are: static (default): elements are arranged in normal order in the document flow. relative: Moves an element a certain distance relative to its original position, but still remains in the document flow. absolute: Removes an element from the document flow and positions it relative to its parent or root element. fixed: Fixed the element in the browser viewport so that it does not move even if the page is scrolled.
Usage of position in CSS
The position property defines the position of an element within the flow of the HTML document and surrounding elements. It can specify whether the element is static, relative, absolute or fixed.
1. static (default value)
Static positioning is the default positioning, and the element occupies normal space in the document flow.
2. relative
Relative positioning moves an element a distance from its normal position without taking it out of the flow of the document.
3. absolute
Absolute positioning removes an element from the document flow and positions it based on its parent or root element.
4. fixed
Fixed positioning fixes the element in the browser viewport and will not move even if the page is scrolled.
Usage
The syntax of the position attribute is as follows:
<code class="css">position: value;</code>
Among them, value can be one of the following values:
Example
The following example will div The element is positioned relative to 10px and moved to the right:
<code class="css">div { position: relative; right: 10px; }</code>
The following example positions the div element absolutely in the lower right corner of the page:
<code class="css">div { position: absolute; bottom: 0; right: 0; }</code>
Note:
The above is the detailed content of How to use position in css. For more information, please follow other related articles on the PHP Chinese website!