Chapter 1

CSS3 Selectors, Box Model & Flexbox

Master selectors, colors, typography, CSS Box Model, Flexbox positioning, and mobile-first Media Queries.

CSS3: Cascading Style Sheets

CSS controls the visual presentation, formatting, and responsive layout of HTML documents.

The CSS Box Model:

Every element on a web page is rendered as a rectangular box comprising 4 layers (from inside out):

  1. Content: The actual text, image, or video.
  2. Padding: Transparent space between the content and the border.
  3. Border: A border surrounding the padding.
  4. Margin: Transparent space outside the border separating the element from neighbors.
Modern Layout: Flexbox
.container {
    display: flex;
    justify-content: space-between; /* Horizontal alignment */
    align-items: center;            /* Vertical alignment */
    flex-wrap: wrap;
}
Hands-on Laboratory Procedures & Shortcuts

Follow the steps below to practice directly on your computer.

Media Query for Mobile Responsiveness:
/* Desktop Styles */
.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}
Watch the video class above while following along with the practical exercises.
Key Summary & Revision Bullet Points

Quick cheat-sheet to review before online examinations.

• Specificity Order: Inline style > ID selector (#id) > Class selector (.class) > Element tag (p).
• box-sizing: border-box; includes padding and border within the element's total width.
Frequently Asked Viva & Exam Questions

Review these standard questions frequently asked in diploma exams and job interviews.

Q1: What does CSS Box Model consist of?
Ans: Content, Padding, Border, and Margin.
Interactive Chapter Quiz

Test your mastery immediately! Click an option to see instant answer feedback.

Q1 Which CSS property defines the space between the content and its border?
A. Margin
B. Padding
C. Outline
D. Border-spacing
Explanation: Padding is the interior clearance between content and border.
Q2 Which selector targets an element with id="mainHeader" in CSS?
A. .mainHeader
B. #mainHeader
C. *mainHeader
D. &mainHeader
Explanation: A hash (#) symbol selects elements by ID.
Q3 Which value of the display property activates CSS Flexbox layout?
A. display: flex
B. display: grid
C. display: inline
D. display: block
Explanation: display: flex turns the element into a flex container.
Q4 What does CSS stand for?
A. Computer Style Sheets
B. Creative Style System
C. Cascading Style Sheets
D. Colorful Style Structure
Explanation: CSS stands for Cascading Style Sheets.
Q5 Which CSS rule is used to apply styles based on different device screen widths?
A. @import
B. @media
C. @keyframes
D. @font-face
Explanation: @media queries enable responsive design adaptation for phones and tablets.