CSS in the presentation layer
IntroducedIn this lesson
| English |
|---|
| inline style |
| class/klæs/ |
| cascade/kəˈskeɪd/ |
| property/ˈprɒpəti/ |
One file styles the site
- CSS builds the presentation layer. A shared stylesheet keeps every page in the same house style.
Stylesheets and inline styles 行内样式
h1 { color: navy; font-size: 28px; text-align: center; }
.highlight { background-color: yellow; font-weight: bold; }
- External stylesheet: a .css file attached to pages. Inline style:
<p style="color: red;">. - Comments:
/* … */.
Match each term to its meaning.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Two places for styles.
Tag styles and classes 类
- A tag style (
h1 {…}) applies to every element of that type. - A class (
.highlight {…}) applies only where used:<p class="highlight">, on any kind of element.
Which applies only where it is used, such as <p class="highlight">?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
A tag style applies to every element of that type.
How is a comment written in CSS?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
HTML uses .
The cascade 层叠
- An inline style overrides attached stylesheets.
- Equally specific rules: the stylesheet attached last wins. Attach with relative paths.
Stylesheet p { color: black; }; one tag <p style="color: red;">: that paragraph is red.
The stylesheet sets p { color: black; }; one tag is <p style="color: red;">. What colour is that paragraph?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The inline style overrides the stylesheet.
Match each property to what it sets.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Each property controls one feature.
Properties
| for | properties |
|---|---|
| background | background-color, background-image |
| font | font-family, font-size, color, text-align, font-weight |
| table | width, padding, border, border-collapse, vertical-align |
End each declaration with a semicolon. A missing ; can stop the next property 属性 working.
External stylesheets style many pages; inline styles one tag. Tag styles apply everywhere; classes only where used. In the cascade, inline beats attached, and the last attached sheet wins ties.
What went wrong? Only the site team sees this.