English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
margin-The top CSS attribute sets the top margin of the element. However, in many cases, likemarginSuch a shorthand CSS attribute is more convenient and preferable to use.
The following table provides usage instructions and version history of this attribute, as well as the syntax of using this attribute in JavaScript scripts.
Default value: | 0 |
---|---|
Applies to: | All elements, but not table displayType (table-caption table inline-elements except for table) outside of the table. . It also applies to ::first-letter. |
Inheritance: | No |
Animatable: | Yes.Please refer to Animation properties. |
Version: | CSS 1,2,3 |
JavaScript syntax: | object.style.marginTop="20px" |
The syntax of this attribute is as follows:
margin-top: length | percentage | auto | initial | inherit
The following examples demonstrate how to use margin-top attribute.
h1 { margin-top: 25px; } p { margin-top: 50px; }Test and see‹/›
The following table describes the value of this attribute.
Value | Description |
---|---|
length | Size value, in units of px, pt, cm, em, etc. Negative values are allowed. |
percentage | Percentage. The percentage is calculated relative to the width of the element's containing block. |
auto | The browser will calculate the margin of the specified element. |
initial | Set this attribute to its default value. |
inherit | If specified, the associated element uses its parent element's margin-The value of the top attribute. |
margin-Browser compatibility of the top attribute, the numbers in the table below represent the minimum version number of browsers that support this attribute; all mainstream browsers support this attribute.
|
Please refer to the following tutorials:CSS Margin,CSS Box Model.
Related attributes:margin,margin-right,margin-bottom,margin-left.