Full Stack JS

Chapter 2
0%

Chapter 2: CSS Fundamentals

Learn to style your web pages — colors, fonts, spacing, and visual effects that bring HTML to life.

Selectors
Box Model
Colors & Fonts
Backgrounds
Pseudo-classes
Quiz

CSS Selectors

CSS is like a paint and decoration crew for your HTML house. The HTML builds the walls, rooms, and doors — CSS decides the wall color, font style, spacing, and where the furniture goes. Selectors are how you point at which room to decorate.

CSS has three main ways to select elements:

HTML — CSS Selectors
Specificity rule: ID selectors (#) are stronger than class selectors (.), which are stronger than element selectors. If two rules conflict, the more specific one wins!
SelectorSymbolExampleSpecificity
Element(none)p { }Low
Class..highlight { }Medium
ID##main-title { }High
Inline stylestyle=""style="color:red"Highest

The Box Model

Every HTML element is like a package being shipped. The content is the item inside, padding is the bubble wrap around it, border is the box itself, and margin is the space between this box and other boxes on the shelf.
HTML — The Box Model
Without box-sizing: border-box, padding and border are added ON TOP of the width. So a width: 200px box with padding: 20px is actually 240px wide! Most developers add * { box-sizing: border-box; } at the top of every stylesheet to avoid this trap.

Colors & Fonts

CSS gives you many ways to set colors and control how text looks. Let's explore them all:

HTML — Colors & Typography

Backgrounds

CSS backgrounds go far beyond just colors. You can use images, gradients, and even layer them together.

HTML — Backgrounds & Gradients

Pseudo-classes & Transitions

Pseudo-classes are like special states an element can be in. Think of a light switch: it can be "off" (default) or "on" (hovered/pressed). Pseudo-classes let you style each state differently.
HTML — Hover Effects & Transitions

🎯 Challenge!

  1. Change the button hover color to green (#00b894)
  2. Make the card rotate slightly on hover using transform: rotate(1deg)
  3. Add a :focus state to the button with a different border color

📝 Chapter 2 Quiz

1. How do you select an element with class "highlight" in CSS?

#highlight { }
.highlight { }
highlight { }
*highlight { }

2. In the CSS box model, what is "padding"?

Space outside the border
The visible edge of the element
Space between content and border
The content itself

3. Which of these is a valid hex color?

#6c5ce7
6c5ce7
&6c5ce7
hex(6c5ce7)

4. Which pseudo-class applies styles when the mouse is over an element?

:active
:focus
:visited
:hover

5. What does box-sizing: border-box do?

Removes all borders
Makes width include padding and border
Adds a box shadow
Centers the element on the page
← Chapter 1: HTML Chapter 3: Flexbox & Grid →