Relentless Feather Unit 3 ยท Read All About It Stage 3 of 7

Unit 3 ยท Stage 3

Text Overlay

Here is the move that makes a page look designed: putting a headline right on top of the photo. You do it with CSS positioning, the most useful layout trick in web design. (pause on a highlighted word to see what it does)

1 How layering works

We added a <div class="hero-text"> inside the hero. To float it over the photo, you use two rules that work as a pair: the container gets position: relative, and the text gets position: absolute.

What this code means
position: relative
On .hero, this makes it the anchor. The overlay will be placed against this box.
position: absolute
On .hero-text, this lifts it out of the normal flow so it can sit on top of the image instead of below it.
bottom, left, right
Set to 0, they pin the overlay to the bottom edge, stretched across the full width.
Native youth in tech: a headline over a powerful photo is how newsrooms tell you what matters most. You decide which story from your community leads the page.

2 Anchor and place the overlay

Give the hero its anchor, then place the text box over the bottom of the photo with a dark see-through background so white text is readable.

What this code means
rgba(0, 0, 0, 0.55)
A see-through black. The last number is how solid it is: 0.55 means 55%, so the photo shows through a little.
padding
Space inside the overlay so the headline does not touch the edges.
๐ŸŽฎ Try it: add .hero { position: relative; }, then a .hero-text rule with position: absolute;, bottom: 0;, left: 0;, right: 0;, background-color: rgba(0, 0, 0, 0.55);, color: #ffffff;, and padding: 24px; then press โ–ถ Run.

๐Ÿค” Quick check before you go on

Which position value lifts an element out of the flow so it can sit on top of another? Type it, then press Submit to unlock the next steps.

3 Style the headline

Now make the overlaid headline big and pull the paragraph in close under it.

What this code means
font-size
34px makes the lead headline stand out over the photo.
margin
0 on the h2 and a small top margin on the paragraph keep the two lines tight together.
๐ŸŽฎ Try it: add .hero-text h2 (margin: 0;, font-size: 34px;) and .hero-text p (margin: 8px 0 0;) then Run.

โœ“ Finish this stage

To complete Stage 3, your .hero-text needs position: absolute and its see-through rgba background. Press Check my work when you are ready. This opens Stage 4 and lets your teacher see that you finished.

YOUR CODE
PREVIEW
Code Glossary
๐ŸŽฏ Your goal for this stage