Export (0) Print
Expand All

margin-top

Sets the height of the top margin of the object.

{ margin-top:sHeight }

sHeight

Variant that specifies or receives one of the following values:

auto

Default. Top margin is set equal to the bottom margin.

height

Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).

For more information about the supported length units, see Length units reference.

percentage

Integer, followed by a percent sign (%). The value is a percentage of the height of the parent object.

The property has a default value of auto and is not inherited.

For inline elements, the value of this property is used to compute the border area of a surrounding inline element, if it is present. This value does not contribute to the height of a line.

Negative margins are supported, except for top and bottom margins on inline objects.

The following example uses the margin-top property to change the margin of the object. This example uses the HR element as a selector and margin1 as a class in an embedded style sheet to set the top margin of the horizontal rule:

<style>
    HR { margin-top: 2cm; }
    .margin1 { margin-top: 4cm; }
</style>
</head>
<body>
<HR onclick="this.className='margin1'" ondblclick="this.className=''">
</style>

This example uses inline scripting to set and reset the margin when the onclick and ondblclick events occur, respectively:

<HR onclick="this.style.marginTop='2cm'" 
ondblclick="this.style.marginTop=''">

A, ABBR, ACRONYM, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, CUSTOM, DD, DEFAULTS, DEL, DFN, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, HN, HR, I, IFRAME, IMG, INPUT TYPE=BUTTON, INPUT TYPE=CHECKBOX, INPUT TYPE=FILE, INPUT TYPE=IMAGE, INPUT TYPE=PASSWORD, INPUT TYPE=RADIO, INPUT TYPE=RESET, INPUT TYPE=SUBMIT, INPUT TYPE=TEXT, INS, LI, OBJECT, OL, P, Q, S, SPAN, SUB, TABLE, TD, TH, TT, U, UL, VAR, XMP

Community Additions

ADD
Show:
© 2014 Microsoft