What is the usage of Class selector and differentiate Class selector from ID
Selector ?Â
Question :
What is the usage of Class selector and differentiate Class selector from ID
Selector ?Â
The class selector selects elements with a specific class attribute. To select elements With a specific class, write a period (.) character, followed by the name of the class. With ID Selector, we can select an element by pointing out the unique ID name set with the id attribute. It we use that selector can be used only once in html document. It we use that selector on More than one element, our code will not pass validation. The difference between the Class and ID selector is: The ID selector consists of a hash (#) followed by the unique ID name of a referring HTML Element. ID selector cannot start with a number and must be at least one character long. They Also case-sensitive, and must exactly match across HTML,CSS and JavaScript.
The ID selector in CSS document:
#para1
{
Text-align: center;
Color: blue; }
Class selector
<style>
.center {
Text-align: center;
Color: blue;
}
</style>
In CSS a class selector starts with a dot (.), like this:
.bank { /* this is the class selector */
Text-color: red;
}