0
0
CSSmarkup~20 mins

Object fit in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Object Fit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visual result of this CSS?
Given this HTML and CSS, what will the image look like inside the 200x200 pixel container?

<div class='box'><img src='image.jpg' alt='Sample' /></div>

.box { width: 200px; height: 200px; } img { width: 100%; height: 100%; object-fit: cover; }
CSS
<div class='box'><img src='image.jpg' alt='Sample' /></div>
.box { width: 200px; height: 200px; }
img { width: 100%; height: 100%; object-fit: cover; }
AThe image is shown at its original size, ignoring container dimensions.
BThe image stretches to fill the container, ignoring aspect ratio, causing distortion.
CThe image fits inside the container without cropping, leaving empty space if aspect ratios differ.
DThe image fills the container completely, cropping parts if needed to keep aspect ratio.
Attempts:
2 left
💡 Hint
Think about how 'cover' affects the image size and cropping.
🧠 Conceptual
intermediate
1:30remaining
Which object-fit value preserves the entire image without cropping?
You want an image inside a fixed-size box to show fully without any part cut off. Which object-fit value should you use?
Acover
Bnone
Ccontain
Dfill
Attempts:
2 left
💡 Hint
This value fits the whole image inside the container, possibly leaving empty space.
📝 Syntax
advanced
1:30remaining
What error does this CSS cause?
Consider this CSS snippet:

img { object-fit: covr; }

What happens when this CSS is applied?
CSS
img { object-fit: covr; }
AThe browser throws a syntax error and stops rendering the page.
BThe browser ignores the invalid value and uses the default 'fill'.
CThe image disappears because of the invalid value.
DThe browser applies 'cover' as a fallback automatically.
Attempts:
2 left
💡 Hint
Browsers handle unknown CSS values by ignoring them.
selector
advanced
2:00remaining
Which CSS selector targets only images with object-fit set to 'contain'?
You want to style only images that have object-fit: contain applied. Which selector works?
Aimg[style*='object-fit: contain']
Bimg:object-fit(contain)
Cimg.object-fit-contain
Dimg[object-fit='contain']
Attempts:
2 left
💡 Hint
Think about how to select elements by inline style attribute.
accessibility
expert
2:30remaining
How does object-fit affect accessibility for screen readers?
Which statement about object-fit and accessibility is true?
AObject-fit affects only visual layout and does not impact screen readers.
BObject-fit changes the image's alt text read by screen readers.
CUsing object-fit requires adding ARIA roles to images for accessibility.
DObject-fit can cause screen readers to skip images if set to 'none'.
Attempts:
2 left
💡 Hint
Consider what screen readers use to understand images.