A. A 200x200 box with the tree.png image stretched to fill the box ignoring aspect ratio.
B. A 200x200 box with the tree.png image repeated to fill the box.
C. A 200x200 box with no image visible because background-repeat is no-repeat.
D. A 200x200 box with the tree.png image centered and fully visible without repeating.
Solution
Step 1: Analyze background-repeat and background-position
background-repeat: no-repeat means the image shows only once. background-position: center places it in the middle.
Step 2: Understand background-size: contain
This scales the image to fit inside the box while keeping its shape, so it is fully visible.
Final Answer:
A 200x200 box with the tree.png image centered and fully visible without repeating. -> Option D
Quick Check:
no-repeat + center + contain = single centered image [OK]
Hint: no-repeat + center + contain = one centered image fully visible [OK]
Common Mistakes:
Thinking no-repeat hides the image
Assuming image repeats anyway
Confusing contain with stretch
4. Identify the error in this CSS code that tries to set a background image:
body {
background-image: url(tree.png);
background-repeat: no-repeat
background-position: center;
}
medium
A. background-position cannot be center.
B. Incorrect URL syntax in background-image.
C. Missing semicolon after background-repeat property.
D. background-repeat should be repeat, not no-repeat.
Solution
Step 1: Check each CSS property line
background-repeat line is missing a semicolon at the end, which breaks CSS parsing.
Step 2: Verify other lines
background-image URL syntax is correct without quotes (allowed but quotes recommended), background-position: center is valid, and no-repeat is a valid value.
Final Answer:
Missing semicolon after background-repeat property. -> Option C
Quick Check:
Every CSS property line needs a semicolon [OK]
Hint: Check for missing semicolons after each CSS property [OK]
Common Mistakes:
Forgetting semicolon after properties
Thinking URL needs quotes always
Misunderstanding valid background-position values
5. You want a background image to cover the entire page, keep its aspect ratio, and stay fixed when scrolling. Which CSS properties and values should you use together?
hard
A. background-image: url('bg.jpg'); background-repeat: repeat; background-position: top left;
B. background-image: url('bg.jpg'); background-size: cover; background-attachment: fixed;
C. background-image: url('bg.jpg'); background-size: contain; background-attachment: scroll;
D. background-image: url('bg.jpg'); background-size: 100% 100%; background-attachment: fixed;
Solution
Step 1: Understand background-size: cover
This makes the image fill the entire area while keeping its shape, cropping if needed.
Step 2: Use background-attachment: fixed
This keeps the background image fixed in place when the user scrolls the page.
Step 3: Check other options
background-image: url('bg.jpg'); background-repeat: repeat; background-position: top left; repeats the image and positions top left, not covering entire page. background-image: url('bg.jpg'); background-size: contain; background-attachment: scroll; uses contain which may leave empty space. background-image: url('bg.jpg'); background-size: 100% 100%; background-attachment: fixed; stretches image ignoring aspect ratio.
Final Answer:
background-image: url('bg.jpg'); background-size: cover; background-attachment: fixed; -> Option B
Quick Check:
cover + fixed = full page image stays on scroll [OK]
Hint: Use cover for full area and fixed to lock image on scroll [OK]
Common Mistakes:
Using contain instead of cover for full coverage
Forgetting background-attachment fixed for fixed image