Skip to lesson content
Web Technologies › Level 11
LEVEL 11 · CSS

CSS Fundamentals

Style meaningful HTML with clear rules, readable text and an understanding of why declarations win.

🎨 CSS⚖️ Cascade🎯 Beginner🧪 Lab + MCQs
01

Learning Objectives

Rules

Read selectors, properties and values, then write valid declarations.

Presentation

Style text, colors and backgrounds without changing document meaning.

Conflicts

Reason about importance, specificity, source order and inheritance.

Practice

Compare controlled examples in the lab and explain the expected result.

02

What CSS Does — Presentation for Structured Content

HTML and CSS work together
HTML · purpose

h1 identifies the page topic; p holds an explanation.

CSS · presentation

Choose readable text, a background and visible focus.

Browser · result

Render the structured document using the applicable styles.

03

CSS Rule Anatomy — Selector, Property and Value

h1 {
  color: #173451;
  font-size: 2rem;
  line-height: 1.2;
}
/* A readable paragraph */
p {
  font-size: 1.125rem;
  line-height: 1.7;
}
04

Inline, Internal and External Styles

Inline

  • A style attribute supplies declarations directly on an element.
  • Useful for a small illustration, but repeated inline styling is difficult to maintain.

Internal

A style element in the document head contains rules for that document. It suits a self-contained exercise or demonstration.

External

A linked CSS file supplies reusable rules. It supports consistent styling across related pages.

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

<style>
  .notice { color: #075a83; }
</style>

<p style="color: #173451;">Workshop information</p>
05

Basic Selectors — Match the Right Elements

p { line-height: 1.7; }
.notice { background: #eef7fc; }
#registration { border: 1px solid #bdd5e6; }
h1, h2 { color: #173451; }
06

Classes and IDs — Reuse Versus Identity

<p id="workshop-note" class="notice featured">Bring your HTML notes.</p>

.notice { padding: 1rem; }
.featured { font-weight: 700; }
07

Relationships and Attribute Selectors

.card p { color: #254864; }
.card > p { margin-top: 0; }
input[type="email"] { border-color: #126d96; }
08

States — hover and focus-visible

A pseudo-class can match an element in a particular state. :hover commonly matches a pointer hovering over an element. :focus-visible matches when the browser considers a visible focus indicator appropriate, including ordinary keyboard use.

a:hover { text-decoration-thickness: 3px; }
button:focus-visible, a:focus-visible {
  outline: 3px solid #126d96;
  outline-offset: 3px;
}
09

Colors — Readable Foreground and Background

.notice {
  color: #173451;
  background-color: #eef7fc;
}
.warning {
  color: rgb(102, 58, 5);
  background-color: hsl(45, 100%, 94%);
}
10

Backgrounds — Images, Gradients and Transparency

.hero {
  color: #ffffff;
  background: linear-gradient(120deg, #10263f, #19445f);
}
11

Fonts and Text — Readability First

body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.125rem;
  line-height: 1.7;
}
h1 { font-weight: 700; line-height: 1.2; }
code { font-family: Consolas, monospace; }
12

Units — px, rem, em and Percentages

px

A CSS pixel is a reference unit used for lengths. It does not always correspond to one physical device pixel.

rem

Relative to the root element’s font size. A useful basis for consistent text and spacing.

em

Relative units whose basis depends on the property. For font-size, em is relative to the parent font size.

%

A relative value with a property-specific basis. Do not assume every percentage is relative to the viewport.

13

The Cascade — Why One Declaration Wins

.note { color: #075a83; }
.note { color: #663399; }

Expected result under the stated assumptions: the later .note rule supplies purple text because both selectors have equal specificity and both declarations are normal author declarations in the same layer.

14

Specificity and !important — Different Decisions

#lesson-note { color: #663399; }
.note { color: #075a83; }

/* Separate example: importance changes the comparison. */
.note { color: #755000 !important; }
#lesson-note { color: #663399; }
15

Inheritance — A Child Can Receive a Parent Value

.workshop { color: #176343; }
.workshop p { margin: 0; }

/* The paragraph can inherit the workshop color. */
16

Premium Visualizer — CSS Rule Selection

Trace matching, cascade context, specificity, source order and the result. This is a guided explanation of the fixed examples shown here. Use the timeline or playback controls; no claim is made that the visualizer evaluates arbitrary CSS.

CSS RULE SELECTION TRACE
Step 1 of 5
STEP 01

Match rules to the element

The paragraph has id="lesson-note" and class="note", so both the ID and class rules match.

<p id="lesson-note" class="note">Workshop notice</p>

What is happening?

Before comparing priorities, check the selector and confirm that the stylesheet loaded. A non-matching rule cannot style this paragraph.

17

Premium Interactive — CSS Conflict Lab

Select a case and inspect its rules.

CSS supplied to the preview

18

Debugging — Inspect Instead of Guessing

File and path

Confirm that the linked stylesheet exists, loads successfully and has the expected content.

Matching

Check spelling, classes, IDs, combinators and the actual element structure.

Conflict

Inspect crossed-out declarations, importance, specificity and order in browser tools.

Value and context

Check syntax, supported values, inheritance and the background or parent that affects the result.

19

Interview Questions — Flip to Explain

QUESTION

Does the last CSS declaration always win?

Click or press Enter to explain
ANSWER

No. It must match, be valid and survive earlier cascade comparisons. Later order resolves an otherwise equal conflict, not every conflict.

QUESTION

Do external styles always outrank internal styles?

Click or press Enter to explain
ANSWER

No. Both can contain author rules. Their cascade context, specificity and order decide applicable conflicts.

QUESTION

What is the difference between class and ID selectors?

Click or press Enter to explain
ANSWER

Classes identify reusable groups and can be combined. An ID identifies one element and should be unique; an ID selector has a higher specificity component.

QUESTION

How does inheritance differ from matching a selector?

Click or press Enter to explain
ANSWER

Inheritance supplies certain parent values when the child has no overriding value. It does not mean the parent selector also matches the child.

QUESTION

Does !important increase selector specificity?

Click or press Enter to explain
ANSWER

No. It flags a declaration as important. Importance is considered at a different cascade stage from selector specificity.

QUESTION

Why keep a unitless line-height?

Click or press Enter to explain
ANSWER

The number acts as a multiplier with the element’s font size, which can make inherited text spacing easier to manage.

QUESTION

Can CSS make a div into a native button?

Click or press Enter to explain
ANSWER

No. Appearance does not provide the semantics and keyboard behavior of a native control.

QUESTION

Why test a background and foreground together?

Click or press Enter to explain
ANSWER

Readability depends on the actual combination, including transparency, parent backgrounds and images behind the text.

20

MCQ Practice — Explain the Winner

PRACTICE

1. Which declaration has the correct CSS syntax?

PRACTICE

2. Which selector matches class="notice"?

PRACTICE

3. What does .card > p match?

PRACTICE

4. Normal author .note rules in one layer have equal specificity. Which wins for the same property?

PRACTICE

5. Which is more specific in the stated simple normal author context?

PRACTICE

6. What does !important do?

PRACTICE

7. Which property is commonly inherited?

PRACTICE

8. With a root font size of 16px, what is 1.125rem?

PRACTICE

9. Which supplies a CSS comment?

PRACTICE

10. Why can opacity: .5 harm a card’s text readability?

PRACTICE

11. Which supports visible keyboard focus?

PRACTICE

12. A rule does not style the expected paragraph. What should you inspect first?

21

Extra Practice — Predict and Verify

Rule repair

Repair color = blue to a valid declaration. Expected: color: blue; is parsed as the requested color.

Class matching

Use class="notice featured" with .notice and .featured rules. Expected: the same element can receive declarations from both.

Child comparison

  • Put one paragraph directly inside a card and another inside a nested section.
  • Expected: .card p matches both; .card > p matches only the direct child.

Equal-rule order

  • Write two .note color rules, then reverse their order.
  • Expected: the later rule wins in the stated equal normal author context.

ID comparison

Put the class rule after a matching ID rule. Expected: the normal ID declaration still wins in the same context.

Inheritance boundary

  • Give a parent a color and border.
  • Expected: the paragraph can inherit the color, while the border does not automatically become the paragraph’s border.

Unit calculation

Assume a 20px parent and set the child font-size to 1.25em. Expected requested font size: 25px under that assumption.

Focus and text growth

  • Keep a visible focus style and increase preview text size.
  • Expected: the active control stays identifiable and text is not clipped.
22

Quick Revision

Syntax: selector { property: value; }
Files: A linked stylesheet must exist and load at the given path.
Selectors: Use classes for reuse and IDs for unique identity.
Relationships: A space means descendant; > means immediate child.
States: Keep keyboard focus visible as well as hover feedback.
Readability: Check the actual foreground and background together.
Units: Relative values have a stated, property-specific basis.
Cascade: Consider context and importance before specificity and ties.
Order: Later order decides an otherwise equal conflict.
Inheritance: Some parent values pass to children; many box properties do not.
23

Glossary — Flip to Learn

TERM

Stylesheet

Click to see meaning
DEFINITION

Stylesheet

A collection of CSS rules defining presentation.

TERM

Selector

Click to see meaning
DEFINITION

Selector

A pattern used to match elements for a rule.

TERM

Declaration

Click to see meaning
DEFINITION

Declaration

A property/value pair with an optional importance flag.

TERM

Property

Click to see meaning
DEFINITION

Property

The aspect of presentation being specified, such as color.

TERM

Cascade

Click to see meaning
DEFINITION

Cascade

The process that resolves competing applicable declarations.

TERM

Specificity

Click to see meaning
DEFINITION

Specificity

Selector components used in the cascade after relevant earlier decisions.

TERM

Source order

Click to see meaning
DEFINITION

Source order

The order used to resolve a remaining equal-priority conflict.

TERM

Inheritance

Click to see meaning
DEFINITION

Inheritance

The transfer of certain parent values when a child lacks an overriding value.

TERM

Pseudo-class

Click to see meaning
DEFINITION

Pseudo-class

A selector feature describing a state or other condition.

TERM

Computed value

Click to see meaning
DEFINITION

Computed value

A property value after the relevant computation stage, before some later layout-dependent resolution.

24

Final Challenge — Style the Semantic Workshop

25

Level 11 Complete?

Before marking complete, write and link a valid stylesheet, demonstrate class matching, explain an equal-rule conflict and an inherited value, and preserve a visible keyboard focus indicator. Completion is a local study milestone, not a score or design certification.