CSS Box Model, Selectors & Specificity

6 min read CSS 9 views

Understanding the CSS Box Model

Every element in CSS is a rectangular box composed of content, padding, border, and margin. Setting box-sizing: border-box ensures padding and borders never expand an element beyond its defined width.

css Example
Run Code
*, *::before, *::after {
    box-sizing: border-box;
}

.card {
    width: 100%;
    max-width: 380px;
    padding: 24px;
    margin: 20px auto;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

Related Tutorials