HTML and CSS · Chapter 6 of 12
First styles
By the end of this chapter you can say what CSS is, link a stylesheet to a page, write rules with type and class selectors, set colours, fonts, sizes, weights, capitals and spacing exactly as a design asks, and find the CSS the browser skipped without a word. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: CSS: the look
- 4 tasks
- HTML and CSS
- In the all labs plan
The first 2 chapters of HTML and CSS are free. This one comes with the all labs plan.
Why you need this
Part 1 gave Parda's site its structure, and every page linked one file you have not opened yet: parda-base.css, Ira's styles for plain elements. They made every h2 maroon and every list's markers gold, but they cannot tell one paragraph from another. Ira's real design does: on the home page each venue is a white card whose name is large and maroon, whose area is small and grey, and whose kind is in small gold-brown capitals; a "Sold out" pill is maroon and a "New" one gold. Sayali has shown the design to the twelve venue owners, and they want their cards to look exactly like it on 4 April.
HTML says what each part of a page is. How it looks (colours, fonts, sizes, spacing, and in part 3 where things sit) is a second language, CSS, Cascading Style Sheets.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
index.html: link the stylesheets
index.html still links part 1's parda-base.css. In its head, replace that link with four links, each <link rel="stylesheet" href="...">, in this order: parda.css (Ira's stylesheet for the whole site), venues.css, badges.css and notice.css. parda-base.css is no longer linked.
With parda.css linked the page shows Parda's look: the body is Parda's cream, #fbf6ee, in Ira's fonts. Keep the page's title, Parda: tickets for Pune's own cinemas and stages, and its body as it is.
- Task 2
venues.css: the venue cards' text
In venues.css, write one rule for each of the three classes in a venue card, with Ira's values. .venue-name (each card's h3): color #7a1c2e, font-size 20px, font-weight 800. .venue-area (the first p): color #74666a, font-size 14px. .venue-kind (the second p): color #8a4b00, font-size 12px, font-weight 700, text-transform uppercase, letter-spacing 2px.
Delete the placeholder rule with the dashed outline. The check reads the computed values on the page, on Kala Talkies' card and Sahyadri Lawns'.
- Task 3
badges.css: the Sold out and New badges
Each badge has two classes: class="badge sold-out" in the launch night table and class="badge new" on Kattaa Cafe Stage's card. In badges.css, write .badge: font-size 12px, font-weight 700, text-transform uppercase, letter-spacing 1px. Then .sold-out: color #ffffff, background-color #7a1c2e. Then .new: color #3d0a15, background-color #f0b94d.
parda.css already makes the badges pills. Delete the placeholder rule with the dashed outline.
- Task 4 · interview question
Interview: notice.css, rules that do nothing
Datta's notice.css styles nothing on the box office notice (the aside with class notice), and the browser shows no error. Fix its rules so that the notice (.notice) has background-color #fff3d6; its title (.notice-title) has color #8a4b00 and font-size 18px; its text (.notice-text) has color #3d0a15; and Datta's name (.notice-sign) has font-size 14px and font-style italic.
Keep the first rule (the margin, the padding and the rounded corners) as it is. When you are done, lab validate notice.css finds no problems.
Ira will ask: the browser shows no error for bad CSS either. What does it do, and how do you find what it skipped?
What you will learn
- A rule: a selector, then declarations, each a property and a value.
- Three ways in: a linked stylesheet, a <style> element, a style attribute, and why a file.
- The browser's own stylesheet: where part 1's Times and 8 px margin came from.
- Type and class selectors: h1 picks every h1; .area picks every element with class area; one element can have several classes.
- Colour and type: color, background-color, font-family, font-size, font-weight, text-align, text-transform, letter-spacing, line-height.
- What the browser skips: silently; lab validate style.css and lab style show it.
More in CSS: the look
Build "First styles" yourself
Parda is launching its first website for Pune's own cinemas and stages. You build it, page by page. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of HTML and CSS are free. This one comes with the all labs plan.