CSS Questions & Answers – Selectors

This set of CSS Multiple Choice Questions & Answers (MCQs) focuses on “Selectors”.

1. What type of selector is used in this case?

p {line-height: 150%;}

a) class Selectors
b) element Selectors
c) id Selectors
d) none of the mentioned
View Answer

Answer: b
Explanation: These selectors are called element selectors and are simply used
as follows:

element-name { /* properties */ }

2. By applying an ___________ a style can be applied to just a single tag.
a) class rule
b) element rule
c) id rule
d) none of the mentioned
View Answer

Answer: c
Explanation: By applying an id rule, a style can be applied to just a single tag. For example, if we name a tag with a unique id attribute as follows

advertisement
advertisement
<tag id="id-value">Affected Text</tag>

3. The _____________ attribute is used to define the name(s) of the class(es) to which a particular tag belongs.
a) class
b) element
c) id
d) none of the mentioned
View Answer

Answer: a
Explanation: Self-explainatory.

4. What will be the output of below mentioned code snippet?

Note: Join free Sanfoundry classes at Telegram or Youtube
p strong {background-color: yellow;}

a) Strong have yellow background
b) Strong element within a p element have a yellow background
c) Both p and strong have yellow background
d) None of the mentioned
View Answer

Answer: b
Explanation: All occurrences of the strong element within a p element have a yellow background.

5. A similar rule called the ____________ is specified using the plus sign (+) and is used to select elements that would be siblings of each other.
a) class selectors
b) attribute selectors
c) adjacent-sibling selector
d) none of the mentioned
View Answer

Answer: c
Explanation: Self-explainatory.

6. Which of the following selectors selects any tag with an id attribute set?

advertisement
a) E#id
b) .class
c) #id
d) *
View Answer
Answer: c
Explanation: Example:#test {color: green;}
/* makes a tag with id=’test’ green */
 
 

advertisement

7. Which of the following selectors selects direct descendents?

a) E &gt; F
b) E F
c) E + F
d) E ~ F
View Answer
Answer: a
Explanation: Example:

body > p {background-color: yellow;}
/* makes all p tags that have the
body tag as their immediate parent
have the background color yellow */
 
 
8. Which of the following selectors selects siblings?

a) E.class
b) E ~ F
c) *
d) E, F, G
View Answer
Answer: b
Explanation: Example:

p ~ strong {font-style: italic;}
/* sets the font style to italic on
all strong tags that have a p tag
as a preceding sibling */

 
 
9. Which of the following selectors selects the specified elements of type E with a particular class value?

a) E.class
b) E ~ F
c) *
d) E, F, G
View Answer
Answer: a
Explanation: Example:

h1.note {text-decoration: underline;}
/* underlines all h1 tags with
class='note' */
 
 
10. Which of the following selectors selects adjacent siblings?

a) E &gt; F
b) E F
c) E + F
d) E ~ F
View Answer
Answer: c
Explanation: Example:

h1 + p {color: red;}
/* makes all p tags that are
immediately preceded by an h1 tag
red */
 
 

Sanfoundry Global Education & Learning Series – CSS.

To practice all areas of CSS, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.