Which CSS selector will select the button element inside the div with class container?
medium
A. container > button.primary
B. div.container button
C. #submit.container
D. button#submit .container
Solution
Step 1: Understand descendant selector
div.container button selects any button inside a div with class container.
Step 2: Check other options for correctness
container > button.primary incorrectly targets a <container> tag (missing dot for class selector). #submit.container is invalid because ID and class cannot be combined like that without space. button#submit .container looks for .container inside button#submit, which is wrong.
Final Answer:
div.container button -> Option B
Quick Check:
Descendant selector = parent child [OK]
Hint: Space means descendant, > means direct child [OK]
Common Mistakes:
Confusing descendant and child selectors
Combining ID and class without space
Wrong order of selectors
4. You want to select all input elements with attribute type='text'. Which CSS selector is correct?
medium
A. All of the above
B. input[type='text']
C. input[type="text"]
D. input[type=text]
Solution
Step 1: Understand attribute selector syntax
CSS attribute selectors can use quotes or no quotes around the value. Both input[type=text] and input[type='text'] are valid.
Step 2: Confirm all options are valid
Using double quotes input[type="text"] is also valid. So all three selectors correctly select input elements with type='text'.
Final Answer:
All of the above -> Option A
Quick Check:
Attribute selectors allow quotes or no quotes [OK]
Hint: Quotes optional in attribute selectors [OK]
Common Mistakes:
Using incorrect attribute syntax
Forgetting quotes when value has spaces
Using wrong attribute name
5. You want to select all li elements that are the first child of their parent ul. Which CSS selector should you use?
hard
A. ul li:first-child
B. ul li:first-of-type
C. ul > li:first-child
D. li:first-child
Solution
Step 1: Understand child combinator and pseudo-class
ul > li:first-child selects li elements that are the first child directly under ul.
Step 2: Compare other options
ul li:first-child selects any li that is first child of its parent inside any ul descendant (could be nested). li:first-child selects any li that is first child anywhere. ul li:first-of-type selects first li of its type inside ul, but not necessarily first child.
Final Answer:
ul > li:first-child -> Option C
Quick Check:
Direct child + first-child pseudo-class = ul > li:first-child [OK]
Hint: Use > for direct child, :first-child for first element [OK]
Common Mistakes:
Confusing :first-child and :first-of-type
Missing direct child combinator >
Selecting nested elements unintentionally
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.