0
What is the difference between ID and CLASS in css selector?
I'd and class selector
4 odpowiedzi
+ 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☺️☺️.