0
0
CSSmarkup~20 mins

Background image in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Background Image Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visible background color when this CSS is applied?
Given the CSS below, what color will you see as the background of the <body> element if the image URL is invalid or missing?
CSS
body {
  background-image: url('nonexistent.jpg');
  background-color: #ffcc00;
}
AThe background will be yellow (#ffcc00) because the image fails to load.
BThe background will be white because the image is missing.
CThe background will be transparent showing the default browser background.
DThe background will be black because the image URL is invalid.
Attempts:
2 left
💡 Hint
Think about what happens when a background image cannot load but a background color is set.
selector
intermediate
2:00remaining
Which CSS selector applies the background image only to <section> elements with class 'hero'?
Choose the CSS selector that correctly applies a background image only to <section> elements that have the class 'hero'.
A#hero section { background-image: url('hero.jpg'); }
Bsection.hero { background-image: url('hero.jpg'); }
Csection .hero { background-image: url('hero.jpg'); }
D.hero section { background-image: url('hero.jpg'); }
Attempts:
2 left
💡 Hint
Remember that the class selector comes immediately after the element name with no space to target that element with the class.
🧠 Conceptual
advanced
2:00remaining
What does the CSS property 'background-size: cover;' do?
Select the correct description of what 'background-size: cover;' does to a background image.
AIt scales the background image to cover the entire container while maintaining aspect ratio, cropping if needed.
BIt stretches the background image to fill the container, possibly distorting it.
CIt repeats the background image to fill the container.
DIt sets the background image size to its original dimensions.
Attempts:
2 left
💡 Hint
Think about how the image fits inside the container without distortion.
accessibility
advanced
2:00remaining
Which practice improves accessibility when using background images for important content?
When a background image contains important information, which approach improves accessibility for screen readers?
AUse CSS background-image only and rely on visual users to see the content.
BUse background images with no fallback text because images are decorative.
CAdd descriptive text in HTML with ARIA labels or hidden text to convey the same information.
DUse background images with low contrast to avoid distracting users.
Attempts:
2 left
💡 Hint
Think about how screen readers access content and what they can read.
📝 Syntax
expert
2:00remaining
What error does this CSS code cause?
Consider the CSS below. What error or issue will occur when the browser tries to apply it?
CSS
div {
  background-image: url('image.png') no-repeat center center;
}
AThe browser will ignore the entire rule because of missing semicolon after url().
BNo error; the background image will display centered and not repeat.
CThe image will repeat because 'no-repeat' is ignored in 'background-image'.
DSyntax error because 'background-image' cannot have multiple values like 'no-repeat' and 'center'.
Attempts:
2 left
💡 Hint
Check which CSS property accepts multiple values and which does not.