Which of the following is a valid example of a class selector in CSS?

Prepare for the uCertify CIW Advanced HTML5 and CSS3 Specialist Exam. Dive into essential topics with flashcards and multiple-choice questions. Enhance your understanding with hints and explanations for each question. Pass your exam confidently!

Multiple Choice

Which of the following is a valid example of a class selector in CSS?

Explanation:
Class selectors in CSS use a dot followed by the class name and apply to any element that has that class, regardless of its tag. The form .right directly demonstrates this: it targets every element with class="right". For example, CSS like .right { color: blue; } will color any element with that class blue, such as <div class="right"> or <span class="right">. The other forms shown are different kinds of selectors. A selector starting with a hash is an ID selector, not a class selector. Writing the word right without a dot would be treated as a tag (type) selector, which would look for an element named <right> (which isn’t a standard HTML tag). The combination div.right is valid and means a div element that also has the class "right"; it uses a class but is more specific than a pure class selector. The direct class-selector example is the clearest demonstration of selecting by class.

Class selectors in CSS use a dot followed by the class name and apply to any element that has that class, regardless of its tag. The form .right directly demonstrates this: it targets every element with class="right". For example, CSS like .right { color: blue; } will color any element with that class blue, such as

or .

The other forms shown are different kinds of selectors. A selector starting with a hash is an ID selector, not a class selector. Writing the word right without a dot would be treated as a tag (type) selector, which would look for an element named (which isn’t a standard HTML tag). The combination div.right is valid and means a div element that also has the class "right"; it uses a class but is more specific than a pure class selector. The direct class-selector example is the clearest demonstration of selecting by class.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy