Web Technology - Old Questions
Question Answer Details
6. What is CSS selector? Compare id selector with class selector.
Answer
AI Generated Answer
AI is thinking...
Official Answer
A CSS selector is the part of a CSS rule set that actually selects the content we want to style. In CSS, selectors are used to target the HTML elements on our web pages that we want to style.
E.g.
Comparison between id selector and class selector
id selector | class selector |
A selector in CSS that styles the element with a specified id. | A selector in CSS that styles the element with a specified class. |
Syntax is: #id{ css declarations; } | Syntax is: .class{ css declarations; } |
Used to apply styling to one specific element. | Used to apply styling to multiple elements. |
It is less used. | It is most used on several elements. |
E.g. #main { background: #000; padding: 10px; color: #fff; width: 100px; } <div id="main"> Welcome </div> | E.g. .main { background: #000; padding: 10px; color: #fff; width: 100px; } <div class="main"> Welcome </div> |