CSS Margin and Padding Properties Box Model
CSS Margin and Padding Properties Box Model
Box model
CSS Margins
Margins are used to create space around elements, outside of any defined borders.
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 70px;
border: 1px solid #4CAF50;
}
</style>
</head>
<body>
<h2>CSS Margins</h2>
</body>
</html>
The CSS margin properties are used to create space
around elements, outside of any defined borders.
With CSS, you have full control over the margins.
There are properties for setting the margin for each
side of an element (top, right, bottom, and left).
Margin - Individual Sides
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
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
Margin - Shorthand Property