+ 5
Still don't get the difference between class and id (not in terms of syntax, but why should i use one instead of another)
22 Respuestas
+ 19
ID is for only one element in the page like footer or header... and class is for repeated things like paragraphs etc
+ 9
The advantage of using ids is that you can overrule certain class properties while retaining others. Let's say you had 4 bullet point <li> elements and you want all of them to be red and bold. You'd make them all <li class="red">, then add a class selector in your CSS like so:
.red { color: red; font-weight: bold }
Now what if you want to make one of those bullet points purple but you also want to keep it bold? You could design a whole new .purple class with a color and font-weight property, but imagine there were 15 properties and you only wanted to change one? That's where IDs come in. They are more important than classes; if a class selector and an ID selector conflict with each other (one says to be red, one says to be purple), then the ID selector's instructions will win out for that particular property. So you could just give it an id, like: <li class="red" id="purpleli">, and then just do this in your CSS: #purpleli { color: purple }, and the resulting text would be purple but also still bold.
+ 8
According to the tutorial ,you can apply ID in only one page or one element on the page whereas Class can be applied for more than one element and page .
+ 5
id is unique to only one element. So we use id to style a single element whereas we use class to style multiple elements.
+ 5
The id attribute is by definition an unique identifier, used for a single element in the currently loaded page. It can be used to style unique elements in your page but as far as I know the trend in frontend development, the use of id as selector to style is discouraged in favor of classes and the id is recommended to be used in JavaScript.
+ 4
I'd can be used only once and class can be used multiple times
+ 3
its like you wanna style a selector with unique styling then u should use id and when u wanna style a bunch of selectors at the same time in a same way then u put those selectors in the same class...:)
+ 3
actually both can be used for the other one. but the id of each element is suppose to be assigned a unique Id name which is normally used to point in scripts though can be used to style too. and class is used mainly to give it some style in some chosen theme of CSS. for example you can add class like class="material-okbtn" to all of the similar buttons but can give each a unique Id to be used in js.
+ 2
ID you can set one especific item and using class you can set all item
+ 2
"Id" is to identify an element unequivocally, while "class" is to identify a group of elements.
+ 2
while the tutorial kept saying you can only use a specific ID once i don't think that's true. i wrote some code in my code playground where i reused the same id in 3 different elements and it worked.
+ 2
ID is unique and therefore can only be used with one element whereas class can be used with group of elements.
+ 1
ID's are used only once per page and the syntax for it in CSS is #(id-name) {(Attributes)}
+ 1
You can put the same class for many elements .
But, "Id" just for one element.
+ 1
You could use the class several times while id can be used only one time in your page.
+ 1
id is for onetime use in one page and class is several times use in one page...
+ 1
id is only element it is use on time but class several time resale same id is nested element
+ 1
Simply, two assigned names, your first name, and last name. when use css styles , run with your first name or last name. mind there will or may be many
same Paul or Smiths in a group of people. got it?
0
Css pictures for the website that didn’t break
0
id is used only once in webpage while class can be reused .