Unit 2 ยท This Is Me In Tech
Stage 4 of 7
Unit 2 ยท Stage 4
We added an image box to each card. Right now the pictures spill out and look messy. You will style the boxes so every image fits its space perfectly. (pause on a highlighted word to see what it does)
Each card now has a <div class="image-box"> at the top with an image inside. You will size that box and hide anything that spills past its edges.
A few properties shape the box that holds each picture.
height180px keeps every card's image the same size.overflowhidden trims anything that sticks out past the box, so images never spill over.border-radiusmargin-bottom.image-box rule with height: 180px;, overflow: hidden;, background-color: #DCE2F0;, border-radius: 6px;, and margin-bottom: 16px; then press โถ Run.What object-fit value fills the box and crops the extra? Type it, then press Submit to unlock the next steps.
Now style the image itself so it fills its box neatly, no matter its shape.
width and height100% so the image stretches to fill its box.object-fitcover fills the whole box and neatly crops the extra, so the image never looks squished..image-box img rule with width: 100%;, height: 100%;, and object-fit: cover; then Run.The photos come from a free placeholder service. When you are ready, you can change the web address inside each <img> tag to any image you want.
To complete Stage 4, your images need object-fit: cover and your .image-box needs overflow: hidden. Press Check my work when you are ready. This opens Stage 5 and lets your teacher see that you finished.