Prelims - CSS margins Flashcards
are used to create space around elements, outside of any defined borders
CSS Margins
CSS has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
All the margin properties can have the following values:
auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
% - specifies a margin in % of the width of the containing element
inherit - specifies that the margin should be inherited from the parent element
Use the margin shorthand property with four values:
top margin is 25px
right margin is 50px
bottom margin is 75px
left margin is 100px
p { margin: 25px 50px 75px 100px; }
You can set the margin property to ____ to horizontally center the element within its container
auto
div { width: 300px; margin: auto; border: 1px solid red; }