Skip to main content

CSS Margins

Published 1 min readMarkdown
CSS Margins

CSS Margins

Margins are used to create space around elements, outside of any defined borders.

image.png

Margin - Individual Sides

CSS has properties for specifying the margin for each side of an element:

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left

Example 1馃憞 image.png

Example 2馃憞 image.png

Margin-Shorthand Property 馃憞

To shorten the code, it is possible to specify all the margin properties in one property.

Diagram 馃憞 image.png

Example1馃憞 image.png

All CSS Margin Properties 馃憞 image.png

The auto Value

You can set the margin property to auto to horizontally center the element within its container.馃憞

image.png

It is possible to give margins a negative value 馃憞

image.png

Margin Collapse馃憞

馃憠 The top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.

馃憠 This does not happen on left and right margins! Only top and bottom margins!

Example馃憞

image.png


image.png> Download our HTML & CSS Visual Treat! ebook Here: Click here

No comments yet. Be the first to comment.

More from this blog