What is the difference between ID and Class selector?
In the CSS, a class selector is a name preceded by a full stop (".") and an ID selector is a name preceded by a hash character ("#"). The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.
For setting styles of different elements you use CSS styles.Before you can apply styles to any HTML element you need to select the elements using the CSS selectors.
The two useful types of selectors are:
id selector the elements with the specified id.
A class selector selects the elements which have a specific class.
For example, if you want to apply styles to elements which have class attribute as class1 then you can use the following definition:
.class1{
//style defintions
}
and if you want apply styles to element which has id of id1 then you can use the following definition:
#id1{
//style defintions
}
With ID selector we can select an element by pointing out the unique ID name set with the id attribute and when we want to style more than one object on a web page, we should be using a class selector.
In the CSS, a class selector is a name preceded by a full stop (".") and an ID selector is a name preceded by a hash character ("#"). The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.
With identity selector we can pick an element through mentioning the particular id name set with the identity characteristic and when we want to style more than one object on an internet page, we need to be the use of a class selector