The top property in CSS is used to set the offset distance of an element relative to the top of its parent element, moving the element up or down. Usage: 1. Specify the length value (such as "px", "em" or "rem"); 2.auto: automatically positioned at the top or bottom; 3.initial: reset to the initial value; 4.inherit: inherit the parent element .
Usage of top attribute in CSS
What is the top attribute?
The top property is used to set the offset distance of an element relative to the top of its parent element. It moves elements up or down.
Usage:
The syntax of the top attribute is as follows:
<code>top: <length> | auto | initial | inherit;</code>
Among them:
: Positions an element at the top or bottom of its parent element, depending on the element's positioning type.
: Resets the element's top property to its initial value.
: Inherit the top attribute value from the parent element.
When to use the top attribute?
The top attribute is typically used in the following situations:Example:
The following example will The element moves 50px down relative to the top of its parent element:
<code class="css">div { top: 50px; }</code>
element up 20% relative to the bottom of its parent element:
<code class="css">div { top: -20%; }</code>
Tip:
The above is the detailed content of How to use top in css. For more information, please follow other related articles on the PHP Chinese website!