mozilla

Revision 236901 of margin-top

  • Revision slug: CSS/margin-top
  • Revision title: margin-top
  • Revision id: 236901
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The margin-top CSS property of an element sets the margin space required on the top of an element. A negative value is also allowed.

<style type="text/css"></style>
  • {{ Xref_cssinitial() }}: 0
  • Applies to: inline and block elements, table, inline-table and table-caption Elements
  • {{ Xref_cssinherited() }}: no
  • Percentages: refer always to width of the containing block
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: the percentage as specified or the absolute length

Syntax

margin-top: {{ Xref_csslength() }}| {{ Xref_csspercentage() }}| {{ Cssxref("inherit") }}| {{ Cssxref("auto") }}

Values

<length>
Specifies a fixed width. See {{ xref_csslength() }} for possible values.
<percentage>
 A {{ xref_csspercentage() }} always relative to the width of the containing block.
auto
See {{ cssxref("margin") }}.

Examples

.content { margin-top: 5%; }
.sidebox { margin-top: 10px; }
.logo    { margin-top: -5px; }
#footer  { margin-top: 1em; } 

Specifications

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 3.0 3.5 1.0 (85)
auto value 1.0 {{ CompatGeckoDesktop("1") }} 6.0 (strict mode) 3.5 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{ CompatGeckoMobile("1") }} 6.0 6.0 1.0

See also

  • {{ CSS_Reference:Margin() }}

{{ languages( { "de": "de/CSS/margin-top", "ja": "ja/CSS/margin-top" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3 id="Summary">Summary</h3>
<p>The<code> margin-top </code>CSS property of an element sets the margin space required on the top of an element. A negative value is also allowed.</p>
<nobr>
<style type="text/css"><![CDATA[.cssprop {
  display:table;
  padding: 0.4em;
  border-left:0.15em solid;
  background-color:#eeeeff
}
.cssprop li {
 display:table-row;
 padding: 3px;
 margin:0;
}
.cssprop li dfn {
  display:table-cell;
  padding: 0 5px;
  border-bottom: none;
  cursor:inherit;
}

]]></style>
<ul class="cssprop"> <li><dfn>{{ Xref_cssinitial() }}:</dfn> <code>0</code></li> <li><dfn>Applies to:</dfn><code> inline </code>and<code> block </code>elements,<code> table</code>,<code> inline-table </code>and<code> table-caption</code> Elements</li> <li><dfn>{{ Xref_cssinherited() }}:</dfn> no</li> <li><dfn>Percentages:</dfn> refer always to <strong>width</strong> of the containing block</li> <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li> <li><dfn>{{ Xref_csscomputed() }}:</dfn> the percentage as specified or the absolute length</li>
</ul></nobr><h3 id="Syntax">Syntax</h3>
<pre class="eval">margin-top: {{ Xref_csslength() }}| {{ Xref_csspercentage() }}| {{ Cssxref("inherit") }}| {{ Cssxref("auto") }}
</pre>
<h3 id="Values">Values</h3>
<dl> <dt>&lt;length&gt;</dt> <dd>Specifies a fixed width. See {{ xref_csslength() }} for possible values.</dd> <dt>&lt;percentage&gt;</dt> <dd> A {{ xref_csspercentage() }} always relative to the <strong>width</strong> of the containing block.</dd> <dt>auto</dt> <dd>See {{ cssxref("margin") }}.</dd>
</dl>
<h3 id="Examples">Examples</h3>
<pre class="eval">.content { margin-top: 5%; }
.sidebox { margin-top: 10px; }
.logo    { margin-top: -5px; }
#footer  { margin-top: 1em; } 
</pre>
<h3 id="Specifications">Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/box.html#margin-properties">CSS 2.1 box #margin</a></li>
</ul>
<h3 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h3>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>3.0</td> <td>3.5</td> <td>1.0 (85)</td> </tr> <tr> <td><code>auto</code> value</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>6.0 (strict mode)</td> <td>3.5</td> <td>1.0 (85)</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>6.0</td> <td>6.0</td> <td>1.0</td> </tr> </tbody> </table>
</div><h3 id="See_also">See also</h3>
<ul>
  <li>{{ CSS_Reference:Margin() }}</li>
</ul>
<p>{{ languages( { "de": "de/CSS/margin-top", "ja": "ja/CSS/margin-top" } ) }}</p>
Revert to this revision