margin-外边距样式属性
- 相对于同级的标签设置偏移量
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
span{
border:1px solid red;
}
.in{
height: 100px;
width: 100px;
}
</style>
</head>
<body>
<div style="border: 1px solid red; height: 300px;width: 300px;margin-bottom: 20px;">
<div class="in" style="background-color: black;"></div>
<div class="in" style="background-color: yellow;margin-left: 20px;"></div>
<div class="in" style="background-color: green;"></div>
</div>
<span>margin样式属性</span>
<span style="margin-left: 20px; margin-right: 30px;margin-top: 20px;magin-bottom: 20px;">margin样式属性</span>
<span>margin样式属性</span>
<div style="border: 1px solid red; height: 300px;width: 300px;margin-top: 20px;margin-bottom: 20px;">
<div class="in" style="background-color: black;"></div>
<div class="in" style="background-color: yellow;margin-left: 20px;"></div>
<div class="in" style="background-color: green;"></div>
</div>
<div style="border: 1px solid red; height: 300px;width: 300px;">
<div class="in" style="background-color: black;"></div>
<div class="in" style="background-color: yellow;margin-left: 20px;"></div>
<div class="in" style="background-color: green;"></div>
</div>
</body>
</html>
效果:
对于块级元素和行内元素都可以设置他们的外边距。但是要注意他们相对的标签。