margin padding in css code example
Example 1: margin css
/* Apply to all four sides */
margin: 1em;
margin: -3px;
/* vertical | horizontal */
margin: 5% auto;
/* top | horizontal | bottom */
margin: 1em auto 2em;
/* top | right | bottom | left */
margin: 2px 1em 0 auto;
/* Global values */
margin: inherit;
margin: initial;
margin: unset;
Example 2: css reset margin padding
* {
margin: 0;
padding: 0;
}
Example 3: css padding vs margin
/* Answer to: "css padding vs margin" */
/*
Margin is outer space of an element, while padding is inner space
of an element. Margin is the space outside the border of an
element, while padding is the space inside the border of it.
Margin accepts the value of auto: margin: auto , but you can't
set padding to auto.
For more information, head over to:
https://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css
*/
Example 4: how do I add a vertical margin in css
subject {
margin-top: /*the size of the margin */ (example: 100px)
/* or */
margin-bottom: /*the size of the margin */ (example: 100px)
}
Example 5: css code for margin
body {
margin: 0px;
}