css中margin屬性的意義是外邊距間隔屬性,可以通過它來實現兩個div之間的間距。
示例:
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>水平方向的兩個盒子</title>
<style>
*{
margin:0;
padding:0;
border:0;
}
body{
font-size: 0;
}
.left{
width: 100px;
height: 100px;
background: red;
display: inline-block;
margin-right: 50px;
font-size: 20px;
}
.right{
width: 100px;
height: 100px;
background: yellow;
display: inline-block;
margin-left: 50px;
font-size: 20px;
}
</style>
</head>
<body>
<div>寬為100px,右邊距為50px</div>
<div>寬為100px,左邊距為50px</div>
</body>
</html>