css · level 2 · unit 6 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
::before and ::after add extra bits with CSS alone.
A is a part of an element that CSS can style as if it were an element of its own. You write it with two colons. ::before adds a box at the start of the element's , and ::after at the end.
They only appear once you give them the content property, usually text in quotes: content: "Tip: ";. An empty content: "" makes a box you can colour and size.
Use them for decoration only. Some tools that read pages aloud skip them, so never put important words there.
<p class="tip">Water your plants in the morning.</p> .tip::before {
content: "Tip: ";
font-weight: bold;
}
.tip {
padding: 12px;
background-color: lightyellow;
} Press show my page to see it here.
The words Tip: appear on the page, but they live in the CSS, not the HTML.
guess first
An ::after with no content. What does it add?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<p class="new">Lemon cake</p> .new::after {
color: red;
font-weight: bold;
}
your turn
Your turn. Star the favourites.
Use ::before and content to put a star or a word in quotes in front of every favourite.
the page you’re styling
<ul>
<li class="fave">Pizza</li>
<li>Broccoli</li>
<li class="fave">Ice cream</li>
</ul>your css
Press show my page to see it here.
- favourites get something in frontnot checked yet
fix it
The arrow never shows up. Fix it!
the page you’re styling
<a class="next" href="https://example.com/chapter-2">Next chapter</a>your css
Press show my page to see it here.
- the arrow sits inside quotesnot checked yet
- The browser skipped the
contentline. What does text in CSS need around it? - Text in
contentmust sit inside quotes. - Write
content: "→";, then press run.
nailed it
you added extras without new tags. :D
::beforeand::afteradd boxes at the start and end.- They need
content, usually text in quotes. - Keep them for decoration, never for important words.
new words in your collection
- pseudo-element
- content
This lesson isn’t saved. A free account remembers every lesson you finish.