Challenge - 5 Problems
Background Size and Position Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What background size will make the image cover the entire element?
You have a div with a background image. Which Tailwind class makes the background image cover the entire div without stretching it out of proportion?
Tailwind
<div class="w-64 h-64 bg-[url('https://via.placeholder.com/150')] bg-no-repeat [CLASS_HERE] bg-center"></div>Attempts:
2 left
💡 Hint
Think about which class makes the image fill the element fully while keeping its aspect ratio.
✗ Incorrect
The 'bg-cover' class scales the background image to cover the entire element area while maintaining its aspect ratio. 'bg-contain' fits the image inside without cropping, 'bg-auto' uses the image's original size, and 'bg-fill' is not a valid Tailwind class.
❓ selector
intermediate1:30remaining
Which Tailwind class centers the background image?
You want the background image to be positioned exactly in the center of the element. Which Tailwind class should you use?
Tailwind
<div class="w-48 h-48 bg-[url('https://via.placeholder.com/100')] bg-no-repeat [CLASS_HERE] bg-cover"></div>Attempts:
2 left
💡 Hint
Think about the class name that suggests the middle position.
✗ Incorrect
The 'bg-center' class positions the background image in the center of the element. Other options position the image at top, bottom, or left edges.
🧠 Conceptual
advanced2:30remaining
What happens if you use both bg-cover and bg-center together?
Consider a div with classes 'bg-cover' and 'bg-center'. What is the combined effect on the background image?
Tailwind
<div class="w-64 h-64 bg-[url('https://via.placeholder.com/200')] bg-no-repeat bg-cover bg-center"></div>Attempts:
2 left
💡 Hint
Think about how 'cover' and 'center' work together for size and position.
✗ Incorrect
'bg-cover' scales the image to cover the entire element, possibly cropping edges. 'bg-center' positions the image in the center. Together, the image fills the div and is centered, cropping if needed.
📝 Syntax
advanced1:30remaining
Which Tailwind class is invalid for background size?
Identify the invalid Tailwind class related to background size from the options below.
Attempts:
2 left
💡 Hint
Check if the class name matches official Tailwind background size utilities.
✗ Incorrect
'bg-stretch' is not a valid Tailwind CSS class. The valid classes for background size are 'bg-auto', 'bg-cover', and 'bg-contain'.
❓ accessibility
expert3:00remaining
How to ensure background images do not reduce accessibility?
Background images can sometimes cause accessibility issues. Which practice helps maintain accessibility when using background images in Tailwind?
Attempts:
2 left
💡 Hint
Think about how screen readers handle background images.
✗ Incorrect
Background images are decorative and cannot have alt text. Important information should not rely solely on background images. Providing meaningful text alternatives elsewhere ensures accessibility.