此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
盒子之间的空间
- margin(外边距)是盒子外面的空间 —— 它和邻居之间的距离。
margin: 30px;在边框外的四边各加 30 像素。- 内边距把内容往里推;外边距把别的盒子推开。
一次只管一边
- 你可以只给一边加间距:
margin-top、margin-right、margin-bottom、margin-left。 - 内边距也一样:
padding-left: 10px;,等等。 - 在标题下面用
margin-bottom,能干净利落地把它和正文分开。
English
<style>
.tag {
background-color: gold;
padding: 6px;
margin-right: 8px;
}
</style>
<span class="tag">news</span>
<span class="tag">sport</span>
常见错误
- 内边距在边框内侧;外边距是边框外侧的空间。
box-sizing: border-box让宽度包含内边距和边框。
现在轮到你
- 外边距是盒子之间的空隙;内边距是盒子里面的空间。
- 先给盒子加外边距,再在标题下方加空间。
探索
margin vs padding
Padding is space inside the border; margin is space outside.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Push the boxes apart from each other. Add margin: 30px; to the .box rule.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Add space below the heading only. Add h1 { margin-bottom: 24px; }.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Space just one side at a time. Give .quote padding-left: 16px; and margin-bottom: 20px;.