CSS Margins
CSS Margins
CSS Margins
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-top
margin-right
margin-bottom
margin-left
<html>
<head>
<style>
div {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: lightblue;
</style>
</head>
<body>
<div>This div element has a top margin of 100px, a right margin of 150px, a
bottom margin of 100px, and a left margin of 80px.</div>
</body>
</html>
margin-top
margin-right
margin-bottom
margin-left
<head>
<style>
div {
background-color: lightblue;
</style>
</head>
<body>
<div>This div element has a top margin of 25px, a right margin of 50px, a
bottom margin of 75px, and a left margin of 100px.</div>
<hr>
</body>
</html>
CSS Padding
Padding is used to create space around an element's content, inside of
any defined borders.
padding-top
padding-right
padding-bottom
padding-left
<html>
<head>
<style>
div {
border: 1px solid black;
background-color: lightblue;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
</style>
</head>
<body>
</body>
</html>
padding-top
padding-right
padding-bottom
padding-left
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 25px 50px 75px 100px;
background-color: lightblue;
}
</style>
</head>
<body>
</body>
</html>