CSS margin 속성은 margin-top, margin-right, margin-bottom 및 margin-left의 약어입니다. 요소 주위의 공간을 지정할 수 있습니다. 우리는 또한 개별 면에 대한 여백을 설정할 수 있습니다.
구문
CSS margin 속성의 구문은 다음과 같습니다 -
Selector {
margin: /*value*/
} 예시
다음 예는 CSS 여백 속성을 보여줍니다 -
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 10px 50px 20px;
padding: 1rem;
border: dashed;
}
p {
text-align: center;
}
#demo {
margin-left: -80px;
box-shadow: inset 0 0 10px brown;
}
</style>
</head>
<body>
<div></div>
<p>This is demo text.</p>
<p id="demo">Another demo text.</p>
<p>This is new demo text.</p>
</body>
</html> 출력
이것은 다음과 같은 출력을 제공합니다 -

예시
<!DOCTYPE html>
<html>
<head>
<style>
ul {
margin: auto;
background-image: linear-gradient(to right, khaki, aliceblue, skyblue, rebeccapurple);
width: 20em;
}
li {
margin-top: 3px;
}
li + li {
margin-left: -20px;
}
li:last-child {
margin-left: 75px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<ul>
<li>This is demo list item.</li>
<li>This is another list item with different style.</li>
<li>This is our third demo text with another style.
</li>
</ul>
</body>
</html> 개요
이것은 다음과 같은 출력을 제공합니다 -
