margin-top
La propietat CSS margin-top
estableix l'àrea de marge en la part superior d'un element . Un valor positiu el situarà més enllà del normal dels seus veïns, mentre que un valor negatiu el situarà més a prop.
/* <length> values */
margin-top: 10px; /* An absolute length */
margin-top: 1em; /* relative to the text size */
margin-top: 5%; /* relative to the nearest block container's width */
/* Keyword values */
margin-top: auto;
/* Global values */
margin-top: inherit;
margin-top: initial;
margin-top: unset;
Initial value | 0 |
---|---|
Applies to | all elements, except elements with table display types other than table-caption , table and inline-table . It also applies to ::first-letter and ::first-line . |
Inherited | no |
Percentages | refer to the width of the containing block |
Computed value | the percentage as specified or the absolute length |
Animation type | a length |
Sintaxi
La propietat margin-top
és especificada amb la paraula clau auto
, o un <length>
, o un <percentage>
. El seu valor pot ser positiu, zero o negatiu.
Valors
<length>
- La grandària del marge com a valor fix.
<percentage>
- La grandària del marge com a percentatge, en relació amb l'amplada del bloc contenidor.
auto
- El navegador selecciona un valor adequat per utilitzar. Veure
margin
.
Sintaxi formal
<length> | <percentage> | auto
Exemples
.content { margin-top: 5%; }
.sidebox { margin-top: 10px; }
.logo { margin-top: -5px; }
#footer { margin-top: 1em; }
Especificacions
Especificació | Estat | Comentsri |
---|---|---|
CSS Basic Box Model The definition of 'margin-top' in that specification. |
Candidate Recommendation | No hi ha cap canvi significatiu |
CSS Transitions The definition of 'margin-top' in that specification. |
Working Draft | Defineix margin-top com animable. |
CSS Level 2 (Revision 1) The definition of 'margin-top' in that specification. |
Recommendation | Elimina el seu efecte en els elements en línia |
CSS Level 1 The definition of 'margin-top' in that specification. |
Recommendation | Definició inicial. |
Navegadors compatibles
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Descripció | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Suport bàsic | 1.0 | (Yes) | 1.0 (1.7 or earlier) | 3.0 | 3.5 | 1.0 (85) |
valor |
1.0 | (Yes) | 1.0 (1.7 or earlier) | 6.0 (strict mode) | 3.5 | 1.0 (85) |
Descripció | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | 1.0 | (Yes) | 1.0 (1) | 6.0 | 6.0 | 1.0 |