CSS Margins. The Margin properties define the space around elements. It is possible to use negative...

22
CSS Margins

Transcript of CSS Margins. The Margin properties define the space around elements. It is possible to use negative...

Page 1: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

CSS Margins

Page 2: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

CSS Margins

The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used to change all of the margins at once. 

Page 3: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Margin Property

The margin property is a shorthand property for setting all of the properties for the four margins in one declaration.

Note: Negative values are allowed.

Inherited: No

Page 4: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Example

h1 {margin: 10px}all four margins will be 10pxh1 {margin: 10px 2%}top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.h1 {margin: 10px 2% -10px}top margin will be 10px, left and right margin will be 2% of the total width of the document, bottom margin will be -10pxh1 {margin: 10px 2% -10px auto}top margin will be 10px, right margin will be 2% of the total width of the document, bottom margin  will be -10px, left margin will be set by the browser

Page 5: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Possible Values

Value Description NN IE

margin-topmargin-rightmargin-bottommargin-left

Sets the properties for the margins. The values comes in % (defines a margin in % of the total height/width of the document), length (defines a fixed margin), and auto (the browser sets a margin).

4.0 4.0

Page 6: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Browser Notes

Note in IE 4.0+: This property does not work with inline elements The "margin-bottom" property does not work with

table cells Note in IE 5.5 Beta 1:

This property works with inline elements Notes in Netscape 4.0+: 

This property does not work properly with inline elements, input fields, images, and list items

This property ignores the bottom margin declaration entirely if a top margin has been specified

Page 7: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Margin-Bottom Property

The margin-bottom property sets the bottom margin of an element.

Note: Negative values are allowed.

Inherited: No

Page 8: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Example

h1{ margin-bottom: 10px}

h2{ margin-bottom: -20px}

Page 9: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Possible Values

Value Description NN IE

auto The browser sets a bottom margin 4.0 4.0

length Defines a fixed bottom margin 4.0 4.0

% Defines a bottom margin in % of the total height of the document

4.0 4.0

Page 10: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Browser Notes

Note in IE 4.0+: This property does not work with table cells or

inline elements

Note in IE 5.5 Beta 1: This property works with inline elements

Notes in Netscape 4.0+:  This property does not work with inline

elements, input fields, images, and list items This property ignores negative values

Page 11: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Margin-Left Property

The margin-left property sets the left margin of an element.

Note: Negative values are allowed.

Inherited: No

Page 12: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Example

h1{ margin-left: 10px}

h2{ margin-left: -20px}

Page 13: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Possible Values

Value Description NN IE

auto The browser sets a left margin 4.0 3.0

length Defines a fixed left margin 4.0 3.0

% Defines a left margin in % of the total width of the document

4.0 3.0

Page 14: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Browser Notes

Note in IE 4.0+: This property does not work with inline

elements Note in IE 5.5 Beta 1: 

This property works with inline elements Notes in Netscape 4.0+: 

This property does not work properly with inline elements, images, and list items

This property ignores negative values on table cells

Page 15: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Margin-Right Property

The margin-right property sets the right margin of an element.

Note: Negative values are allowed.

Inherited: No

Page 16: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Example

h1{ margin-right: 10px}

h2{ margin-right: -20px}

Page 17: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Possible Values

Value Description NN IE

auto The browser sets a right margin 4.0 3.0

length Defines a fixed right margin 4.0 3.0

% Defines a right margin in % of the total width of the document

4.0 3.0

Page 18: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Browser Notes

Note in IE 4.0+: This property does not work with inline

elements Note in IE 5.5 Beta 1: 

This property works with inline elements Notes in Netscape 4.0+: 

This property does not work properly with inline elements, images, and list items

This property ignores negative values on table cells

Page 19: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Margin-Top Property

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

Note: Negative values are allowed.

Inherited: No

Page 20: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Example

h1{ margin-top: 10px}

h2{ margin-top: -20px}

Page 21: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Possible Values

Value Description NN IE

auto The browser sets a top margin 4.0 3.0

length Defines a fixed top margin 4.0 3.0

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

4.0 3.0

Page 22: CSS Margins. The Margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom,

Browser Notes

Note in IE 4.0+: This property does not work with inline elements

Note in IE 5.5 Beta 1:  This property works with inline elements

Notes in Netscape 4.0+:  This property does not work with inline elements,

images, and list items This property ignores negative values on inline

elements, images, list items, and table cells