CSS (Fundamentals, Colors, and Styling) 3 — Questions and Answers
Question 1: Which CSS property sets the background color of an element?
- bgcolor
- background-color (Correct answer)
- color-background
- fill
Correct answer: background-color
background-color sets the color behind the element's content.
Question 2: What is the default value of the 'color' property if not specified?
- Always black
- Inherited from the parent (Correct answer)
- White
- Transparent
Correct answer: Inherited from the parent
The color property is inherited, so it takes the parent's value by default.
Question 3: Which of these is a valid way to apply CSS directly to one HTML element?
- Inline style attribute (Correct answer)
- A <css> tag
- The data-style attribute
- A .style file link
Correct answer: Inline style attribute
Inline CSS uses the style attribute on the element itself.
Question 4: What does the CSS property 'opacity: 0.5;' do?
- Hides the element completely
- Makes the element 50% transparent (Correct answer)
- Doubles the element size
- Blurs the element
Correct answer: Makes the element 50% transparent
Opacity 0.5 renders the element at 50% transparency.
Question 5: Which shorthand hex code is equivalent to #FF0000?
- #F00 (Correct answer)
- #FF0
- #R00
- #100
Correct answer: #F00
#F00 expands to #FF0000, which is pure red.
Question 6: How is an external stylesheet linked to an HTML document?
- <style src='file.css'>
- <link rel='stylesheet' href='file.css'> (Correct answer)
- <css href='file.css'>
- @import only in HTML
Correct answer: <link rel='stylesheet' href='file.css'>
A <link> element with rel='stylesheet' references an external CSS file.
Question 7: What color does the named CSS keyword 'transparent' produce?
- Pure white
- Pure black
- Fully see-through (Correct answer)
- Light gray
Correct answer: Fully see-through
The 'transparent' keyword equals a fully transparent color (alpha 0).
Which CSS property sets the background color of an element?