Box Model Concept
In CSS, absolutely everything — from a tiny icon to a huge footer — is a rectangle. Even if an element looks like a circle, to the browser it's still a square with cut corners.
Four Layers of Your Design:
- Content: The element's core. Text, image, or video. Its size can be set with
widthandheightproperties. - Padding: The layer between content and border.
- Important: Padding increases the clickable area of an element (e.g., a button).
- Border: The block's boundary. It has thickness, style, and color.
- Margin: The element's " personal space " . Separates it from neighbors.
Modern Approach: Logical Properties
Previously we only used top/right/bottom/left. But in modern web we often work with vertical languages or Arabic script. Logical properties came to help:
- Block: Text flow direction (usually top to bottom).
- Inline: Line direction (left to right).
- Instead of
padding-left, pros increasingly writepadding-inline-start.
Tip
Imagine a block as an onion. Peeling layer by layer, you reach the very essence — content. Understanding how these layers interact eliminates 90% of interface layout problems.