0
0
Tailwindmarkup~20 mins

Object-fit for images and media in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Object-fit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What will the image look like with object-fit: cover?

Consider an image inside a fixed 200x200 pixel container. The image is larger and rectangular. The CSS class object-cover is applied to the image.

What will the image look like inside the container?

Tailwind
<div class="w-50 h-50 border border-gray-400">
  <img src="https://via.placeholder.com/400x300" alt="Sample" class="object-cover w-full h-full" />
</div>
AThe image will stretch to fill the container, ignoring its aspect ratio.
BThe image will be fully visible, scaled down to fit inside the container with empty space around it.
CThe image will fill the container completely, cropping parts that overflow while keeping aspect ratio.
DThe image will be centered but not resized, showing only the top-left part.
Attempts:
2 left
💡 Hint

Think about how cover behaves: it fills the container while keeping the image's shape, even if some parts get cut off.

selector
intermediate
1:30remaining
Which Tailwind class sets object-fit: contain?

You want an image to scale down to fit inside its container without cropping, showing the entire image with possible empty space.

Which Tailwind CSS class achieves this?

Aobject-contain
Bobject-fill
Cobject-cover
Dobject-scale-down
Attempts:
2 left
💡 Hint

Remember, contain keeps the whole image visible inside the container.

🧠 Conceptual
advanced
2:00remaining
What happens if you use object-fit: scale-down on an image?

Given an image inside a container, what is the behavior of object-fit: scale-down?

AThe image is always scaled up to fill the container, cropping if needed.
BThe image is scaled down to fit inside the container only if it is larger; otherwise, it keeps its original size.
CThe image is centered and clipped without resizing.
DThe image is stretched to fill the container ignoring aspect ratio.
Attempts:
2 left
💡 Hint

Think about when the image is smaller or larger than the container.

accessibility
advanced
1:30remaining
How to ensure images with object-fit remain accessible?

You use object-fit to style images on your webpage. What is the best practice to keep images accessible?

AAlways add descriptive <code>alt</code> text and ensure images are keyboard focusable if interactive.
BUse empty <code>alt</code> attributes to hide images from screen readers.
CAvoid using <code>alt</code> attributes because <code>object-fit</code> changes image shape.
DAdd <code>aria-hidden="true"</code> to all images styled with <code>object-fit</code>.
Attempts:
2 left
💡 Hint

Think about screen readers and users who rely on them.

layout
expert
2:30remaining
Which Tailwind classes create a responsive square container with an image that covers it fully?

You want a square container that adjusts size with the screen width. Inside it, an image should fill the container completely, cropping if needed, and keep its aspect ratio.

Which combination of Tailwind CSS classes achieves this?

AUse <code>aspect-square max-w-xs</code> on the container and <code>object-scale-down w-full h-full</code> on the image.
BUse <code>w-64 h-64</code> on the container and <code>object-contain w-full h-full</code> on the image.
CUse <code>aspect-video w-full</code> on the container and <code>object-fill w-full h-full</code> on the image.
DUse <code>aspect-square w-full max-w-sm</code> on the container and <code>object-cover w-full h-full</code> on the image.
Attempts:
2 left
💡 Hint

Remember aspect-square keeps a square ratio and object-cover fills the container cropping if needed.