CSS GUIDE MARGIN TOP

From CDOT Wiki
Jump to: navigation, search

Summary

margin-top property sets the top margin of an element.

  • Initial value: depends on user agent
  • Applies to: all elements
  • Inherited: no
  • Percentages: yes, refers to the width of containing block
  • Media: visual
  • Computed value: as specified

Syntax

h1 { margin-top: value }

Legal Values

auto

The browser sets a top margin.

length

Defines a fixed top margin.

percentage

Defines a top margin in % of the total height of the document.

Mozilla Recommended Values

Usage Examples

h1 { margin-top: 10px }
h2 { margin-top: -20px }
h3 { margin-top: 1em }
<p style="margin-top : 2em;">
This paragraph has a 2 em margin top.
</p>

Notes

  • Negative values are allowed

Specification Conformance

Browser Compatibility

  • Netscape 4, 6, 7
  • Mozilla 1
  • Firefox 1, 1.5, 2
  • Internet Explorer 3, 4, 5, 6
  • Opera 3, 4, 5, 6, 7, 8
  • Safari 1

See Also