0
What is the difference between ID and CLASS in css selector?
I'd and class selector
4 Respostas
+ 8
Id is unique it means it can be assigned to only one element.
Where as class can be assigned to more than one elements.
Class comes handy when you have to apply same css to a bunch a elements.
+ 2
The id is used to identify a particular element and can not be repeated within the html. In contrast, class, you can use it as many times as you wish to give css styles to one or multiple elements (<div> </ div>, <p> </ p> <section> </ section>, etc.) within the html. On the other hand, an html tag can contain multiple class but not multiple id (only one). in this way you can summarize the css code in case different elements share the same style ... example:
<div id=âtext-infoâ class=âtop infoâ></div>
<div class=âtop examplesâ></div>
<p class=âinfoâ></p>
ââ css ââ
#text-info{
border-radious: 15px;
}
.top{
top: 10px;
}
.info{
font-size: 24px;
}
.examples{
font-size: 20px;
color: #ff0000;
}
ââââââââââ-
#text-info => only for first âdivâ
.top => for both âdivâ
.info => for first âdivâ and âpâ
.examples => for seccond âdivâ
âââââââââââ
REGARDS!
+ 1
Id has to be unique,
Same class can be used on multiple elements.
https://duckduckgo.com/?q=What+is+the+difference+between+ID+and+CLASS+in+css+selector%3F+I%27d+and+class+selector&t=brave&ia=qa
0
ID :
YOU CAN ONLY HAVE SINGLE ID NAME MEANS YOU CAN USE ID IN ANY OF HTML TAGS YOU WANT BUT ID NAME GIVEN TO ONE TAG CANNOT BE USED IN ANOTHER.
EG :
<p id="paragraph"></p>
THAN YOU CANT USE ID NAME paragraph IN ANY OTHER TAG HAVING ID.
YOU CAN SELECT IT USING #.
CLASS :
YOU CAN HAVE CLASS NAME AS MUCH AS YOU WANT.
EG :
<p class="paragraph"></p>
<p class="paragraph"></p>
YOU CAN HAVE MULTIPLE CLASS HAVING paragraph AS A NAME.
YOU CAN SELECT IT USING (.).
Hope this helpsâșïžâșïž.