NexusBerry Training & Solutions
    NexusBerry Training & Solutions

    NexusBerry provides cutting-edge training and solutions for modern technology needs.

    About Us

    • Privacy Policy
    • Blog
    • Ruls and Regulations
    • Forms

    NexusBerry

    • Contact Us
    • About Us
    • Job Openings
    • Payment Methods

    Resources

    • Internship
    • Tutorials
    • Fee Structure
    • Admission Form

    AI & Data Science

    • Data Science Professional with Python & Applied Analytics
    • Full Stack Python Developer
    • Advanced Data Analytics Professional with Python and BI Tools
    • Agentic AI Engineer – GenAI, RAG & Autonomous Agents
    • AI Machine Learning Engineer with Python & Deep Learning
    • Python Programming for Software & AI Careers

    Software Engineering

    • Modern Frontend Developer with React & Next.js
    • MEAN Stack Mastery: Empower Your Web Development Skills for Modern Applications
    • Advanced Web Development with ASP.NET Core and Angular.js
    • Unlocking the Potential of PHP Laravel with Vue.js: A Comprehensive Training Course for Web Development Success
    • Django & React: Build Full-Stack Modern, Scalable Web Applications
    • Full Stack JavaScript Developer Specialization: Building Web and Mobile Apps with MERN Stack and React Native
    • Next.js: The Modern Path to Full Stack Web Development
    • Python Full Stack Web Development With Django
    • MERN Full Stack Web Development With Nextjs & GenAI

    Mobile App Development

    • Flutter App Development Course: Masterclass with Real-World Projects
    • React Native for Android and iOS App Development

    Digital Marketing

    • Social Media Marketing Course
    • SEO (Search Engine Optimization) Course
    • Full Stack Digital Marketing Course

    Creative Design

    • Master Video Editing: From Beginner to Pro Storyteller
    • Full Stack Designing & Video Editing Course
    • UI/UX Designing
    • Professional Graphic Design Masterclass: Master Visual Branding & AI Tools

    IT Infrastructure & Security

    • The Ultimate Cybersecurity Course: Web App Protection from Scratch
    • DevOps and Cloud Computing
    • CCNA Course

    © Copyright 2025, All Rights Reserved By NexusBerry Training & Solutions

    1. Home
    2. Tutorials
    3. Web Development Fundamentals
    4. Lecture 3: CSS Fundamentals and The Box Model
    css 1/3

    Lecture 3: CSS Fundamentals and The Box Model

    Subscribe to our channel

    Every visual decision on the web comes down to CSS. This is where you learn to control it — not guess at it.


    What You'll Learn

    The building blocks every front-end developer uses every single day:

    • 📝 CSS Rule Anatomy — how selectors, properties, and values fit together into rules that style your page
    • 🔗 3 Ways to Add CSS — inline, internal, and external stylesheets, and when to use each
    • 🎯 Selectors & Specificity — element, class, and ID selectors, plus how browsers decide which rule wins when styles conflict
    • 📦 The Box Model — the single most important concept in CSS; understanding how margin, border, padding, and content interact
    • 🎨 Color Formats — named colors, hex codes, RGB, and RGBA for transparency
    • 🛠️ The Professional Reset — the one box-sizing: border-box rule every real project starts with, and why it saves you from layout headaches

    Why This Matters

    Most CSS frustration — elements the wrong size, layouts breaking unexpectedly, styles not applying — comes from not understanding the Box Model and specificity. Once these two concepts click, CSS stops feeling like guesswork and starts feeling like a tool you control.


    Before You Watch

    Make sure you've completed Lecture 2: HTML Foundations. You should be comfortable with:

    • Writing HTML tags and nesting elements
    • Understanding parent/child relationships in HTML
    • The basic structure of a webpage (head, body, etc.)

    📎 The cheatsheet for this lecture is attached below the video. The Box Model diagram and the Common Properties Quick Reference table are worth keeping open as you code along!

    CSS Fundamentals & The Box Model Cheatsheet

    Quick reference for all CSS concepts covered in Lecture 3.


    CSS Rule Anatomy

    Every CSS rule follows this structure:

    1selector {
    2 property: value;
    3 property: value;
    4}

    Example:

    1h1 {
    2 color: #E04A7A;
    3 font-size: 32px;
    4 text-align: center;
    5}

    Key: selector → targets HTML elements | property → what to change | value → how to change it


    3 Ways to Add CSS

    Method

    Syntax

    When to Use

    Inline

    <p style="color: red;">

    Quick testing only — avoid in production

    Internal

    <style> in <head>

    Single-page projects, learning

    External

    <link rel="stylesheet" href="style.css">

    Production — best practice


    Selector Types Reference

    Selector

    Syntax

    Example

    Specificity

    Element

    tagname

    p { }

    0-0-1

    Class

    .classname

    .highlight { }

    0-1-0

    ID

    #idname

    #header { }

    1-0-0

    Grouping

    sel1, sel2

    h1, h2 { }

    Individual

    Pseudo-class

    sel:state

    a:hover { }

    0-1-1

    Remember: Dot . goes in CSS, NOT in HTML!

    1<!-- HTML — no dot -->
    2<p class="highlight">Text</p>
    1/* CSS — dot required */
    2.highlight { color: red; }

    Specificity Scoring (0-0-0)

    1Inline styles → 1-0-0-0 (highest — avoid!)
    2ID selectors → 0-1-0-0
    3Class selectors → 0-0-1-0
    4Element selectors→ 0-0-0-1 (lowest)

    Rules:

    1. Higher specificity ALWAYS wins
    2. Equal specificity → last rule wins (the cascade)
    3. !important overrides everything (never use it)

    Example:

    1p { color: blue; } /* 0-0-1 */
    2.special { color: red; } /* 0-1-0 ← WINS */
    3#unique { color: green; } /* 1-0-0 ← WINS over both */

    The Box Model

    1┌──────────────────────────────────────┐
    2│ MARGIN │
    3│ ┌────────────────────────────────┐ │
    4│ │ BORDER │ │
    5│ │ ┌──────────────────────────┐ │ │
    6│ │ │ PADDING │ │ │
    7│ │ │ ┌──────────────────┐ │ │ │
    8│ │ │ │ CONTENT │ │ │ │
    9│ │ │ │ (text, images) │ │ │ │
    10│ │ │ └──────────────────┘ │ │ │
    11│ │ └──────────────────────────┘ │ │
    12│ └────────────────────────────────┘ │
    13└──────────────────────────────────────┘

    Analogy: Photo (content) → Matting (padding) → Frame (border) → Wall space (margin)

    The Professional Reset

    1*, *::before, *::after {
    2 box-sizing: border-box;
    3}

    Box Sizing

    Width Includes

    Total Width

    content-box (default)

    Content only

    content + padding + border

    border-box (professional)

    Content + padding + border

    Exactly what you set

    Example: width: 300px; padding: 20px; border: 5px solid;

    • content-box → total = 300 + 40 + 10 = 350px
    • border-box → total = 300px (padding + border eat into content)

    CSS Colors

    Format

    Syntax

    Example

    Named

    color: red;

    140+ named colors

    Hex

    color: #RRGGBB;

    #990147 (NexusBerry)

    RGB

    color: rgb(R, G, B);

    rgb(153, 1, 71)

    RGBA

    color: rgba(R, G, B, A);

    rgba(0, 0, 0, 0.5) — 50% transparent

    Pro Tip: Hex is used ~70% of the time in production. Learn to read hex values.


    Common CSS Properties Quick Reference

    What You Want

    Property

    Example

    Text color

    color

    color: #333;

    Background color

    background-color

    background-color: #080D2B;

    Font size

    font-size

    font-size: 18px;

    Font family

    font-family

    font-family: 'Segoe UI', sans-serif;

    Bold text

    font-weight

    font-weight: bold; or 700

    Text alignment

    text-align

    text-align: center;

    Line spacing

    line-height

    line-height: 1.6;

    Letter spacing

    letter-spacing

    letter-spacing: 0.05em;

    Inner spacing

    padding

    padding: 20px;

    Outer spacing

    margin

    margin: 10px;

    Center horizontally

    margin

    margin: 0 auto; (needs set width)

    Border

    border

    border: 2px solid #990147;

    Rounded corners

    border-radius

    border-radius: 10px;

    Circle shape

    border-radius

    border-radius: 50%; (on square element)

    Drop shadow

    box-shadow

    box-shadow: 4px 8px 16px rgba(0,0,0,0.3);

    Remove underlines

    text-decoration

    text-decoration: none;

    Remove list bullets

    list-style

    list-style: none;

    Width

    width

    width: 350px;


    Common Mistakes to Avoid

    1. Missing Semicolons

    1/* WRONG — font-size also breaks! */
    2h1 {
    3 color: blue
    4 font-size: 24px;
    5}
    6
    7/* CORRECT */
    8h1 {
    9 color: blue;
    10 font-size: 24px;
    11}

    2. Dot in HTML Class Attribute

    1<!-- WRONG -->
    2<p class=".highlight">Text</p>
    3
    4<!-- CORRECT -->
    5<p class="highlight">Text</p>

    3. Misspelling Properties

    1/* WRONG — CSS fails silently! */
    2h1 { colour: red; }
    3
    4/* CORRECT */
    5h1 { color: red; }

    4. Forgetting border-box

    1/* WRONG — element will be wider than 300px */
    2.box {
    3 width: 300px;
    4 padding: 20px;
    5 border: 5px solid black;
    6 /* Total: 350px! */
    7}
    8
    9/* CORRECT — element is exactly 300px */
    10*, *::before, *::after {
    11 box-sizing: border-box;
    12}
    13.box {
    14 width: 300px;
    15 padding: 20px;
    16 border: 5px solid black;
    17 /* Total: 300px */
    18}

    VS Code Shortcuts

    Shortcut

    Action

    Ctrl + Space

    CSS property autocomplete

    Ctrl + /

    Toggle comment (CSS: /* */)

    Ctrl + D

    Select next occurrence

    Alt + Up/Down

    Move line up/down

    Shift + Alt + Down

    Duplicate line

    Type bgc + Tab

    Emmet: background-color: #fff;

    Type fz + Tab

    Emmet: font-size: ;

    Type bd + Tab

    Emmet: border: ;

    Type m0a + Tab

    Emmet: margin: 0 auto;


    Chrome DevTools: CSS Inspection

    Opening DevTools

    • F12 or Ctrl + Shift + I
    • Right-click any element → "Inspect"

    Styles Panel

    • Shows ALL CSS rules applied to the selected element
    • Strikethrough = overridden by a more specific rule
    • Click any value to edit live
    • Toggle checkboxes to enable/disable properties

    Box Model Visualizer

    • Located in the "Computed" tab (or bottom of Styles panel)
    • Blue = content, Green = padding, Yellow = border, Orange = margin
    • Hover over each section to highlight it on the page

    Contrast Checker

    • Click any color value in Styles panel
    • Shows contrast ratio against background
    • Green checkmark = passes WCAG, Red = fails

    What's Next?

    In Lecture 4: Modern Dashboard Layout, you'll learn:

    • Flexbox — One-dimensional layout (rows OR columns)
    • CSS Grid — Two-dimensional layout (rows AND columns)
    • Responsive design basics — Making layouts adapt to screen sizes
    • Building a dashboard with multiple cards side by side

    Keep this cheatsheet handy while working on your assignment!

    All Web Development Fundamentals Tutorials