UNIT 2 • STAGE 4 OF 7
Add image containers to your cards and control how images display
Your Flexbox layout is working - three white cards sit side by side. Now we want to add a visual image area to the top of each card, so you can eventually drop in your own photos or artwork.
In this stage, you'll add a <div class="image-box"> inside each card and style it with CSS.
From Stage 3, your .container uses padding: 40px 20px. When padding has two numbers, the first number sets the top and bottom (40px each side), and the second number sets the left and right (20px each side). It's a shortcut so you don't have to write four separate values!
Inside each <section class="card">, add a <div class="image-box"> before the <h2>. Do this for all three cards.
Add the <div class="image-box"></div> line to all three cards. Right now the div is empty - when you add the CSS in Step 3, it will turn into a visible colored box at the top of each card.
Now let's give that empty div some size and color so it becomes a visible, fixed-height box.
Here's what each line does and why:
height: 180px - sets a fixed height of 180 pixels. Without this, an empty <div> has zero height and would be completely invisible. The px stands for pixels - the tiny dots that make up your screen.overflow: hidden - think of the image-box like a picture frame. If the photo is bigger than the frame, overflow: hidden clips it so only what fits inside shows. Without it, the image would spill out past the edges of the box.background-color: #DCE2F0 - a soft blue-grey placeholder. Before any image is loaded, you'll see this color fill the box so you know the space is there. Once you add an image, it will cover this color completely.border-radius: 6px - softens the corners of the image-box. Your card already has border-radius: 8px, so using 6px here makes the image-box sit just inside the card's rounded corners - a little less round so it doesn't look like it's breaking out of the card.margin-bottom: 16px - adds 16 pixels of space below the image box, so the heading underneath has room to breathe. Think of margin like personal space around an element - it pushes other elements away.Let's put an actual image inside the first card's image-box. For now, use a free placeholder image from the web.
picsum.photos is a free service that gives you random placeholder photos. The two numbers at the end (320/180) set the image width and height in pixels - 320 wide, 180 tall. The word after seed/ is just a label that picks a specific random photo - change it to anything you like.
Later, you can swap the src value for a photo that's meaningful to you - your community, your art, your land. The image-box will hold whatever you give it.
Right now the image might not fill the box perfectly - it could be the wrong size or leave white gaps. object-fit: cover fixes that by making the image fill its container completely, without stretching or squishing.
Notice the selector .image-box img - that space between the two words means "any img that is inside a .image-box." This keeps your style from affecting images elsewhere on the page.
object-fit: cover is like choosing "Fill" when you set a desktop wallpaper - the image fills the whole frame and any overflow is hidden outside the edges.
Add images to all three cards, then experiment:
picsum.photos/seed/nature/320/180 or picsum.photos/seed/river/320/180height: 180px to 220px - how does a taller box feel?background-color to a color from your Tribal nation's paletteYou've added image boxes with controlled sizing using object-fit: cover. In Stage 5, we'll style the text inside the cards - headings, paragraphs, and typography!