Openwave Mobile Browser 6.1 and 6.2: XHTML Mobile Profile and CSS Reference

Section 25 out of 38 total sections
Current chapter: CSS Reference

Margin Properties

You can use the margin properties to add space between an element's border and the edge of the screen or adjacent elements. The color or image of the margin area is set by the containing element, not by the element itself. Elements have no margins unless you set them with the margin properties or they inherit a margin from a parent element.

Margins are described in The CSS Box Model.



margin-top, margin-right, margin-bottom, margin-left

Sets the size of the top, right, bottom, or left margin.

Values

em, ex, cm, mm, in, pt, pc, px, %, auto, inherit

For more information, see Units of Measure, Percentage, and Keywords.

Default Value

0

Useful For

Block elements and replaced inline elements (such as <img> and <object>).

Inherited

No.

Notes

Percentage values are relative to the width of the containing block.

Example

div {margin-top: 6pt}

Adds 6 points of vertical space above between each <div> element and the element above it, or the top of the screen.



margin

A shorthand property that sets the size of all four margins: all at once, in sets, or individually, as described in The CSS Box Model.

Values

em, ex, cm, mm, in, pt, pc, px, %, auto, inherit

For more information, see Units of Measure, Percentage, and Keywords.

Default Value

None.

Useful For

Block elements and replaced inline elements (such as <img> and <object>).

Inherited

No.

Notes

Percentage values are relative to the width of the containing block.

Example
h1 {margin: 6pt}

Adds 6 points between each <h1> element and the elements above and below it, as well as between the left and right edges of the screen.

h1 {margin: 1em 2em}

Sets top and bottom margins to 1 em, right and left margins to 2 ems.