Spacing — margin and padding · רווחים — שוליים ורפידה
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
Space between boxes
- Margin is the space outside a box — the gap to its neighbours.
margin: 30px;adds 30 pixels on all four sides, outside the border.- Padding pushes the content in; margin pushes other boxes away.
One side at a time
- You can space just one side:
margin-top,margin-right,margin-bottom,margin-left. - The same works for padding:
padding-left: 10px;, and so on. margin-bottomunder a heading neatly separates it from the text.
<style>
.tag {
background-color: gold;
padding: 6px;
margin-right: 8px;
}
</style>
<span class="tag">news</span>
<span class="tag">sport</span>
Common mistakes
- Padding is inside the border; margin is the space outside it.
box-sizing: border-boxmakes the width include padding and border.
Now you try
- Margin is the gap between boxes; padding is the space inside one.
- Add margin around a box, then space below a heading.
Explore · חקור
margin vs padding · שוליים לעומת רפידה
Padding is space inside the border; margin is space outside. · רפידה היא מרחב בתוך הגבול; שוליים הם מרחב מחוץ לו.
Push the boxes apart from each other. Add margin: 30px; to the .box rule. · הרחק את הקופסאות זו מזו. הוסף margin: 30px; לכלל .box.
Add space below the heading only. Add h1 { margin-bottom: 24px; }. · הוסף רווח תחת הכותרת בלבד. הוסף h1 { margin-bottom: 24px; }.