+ 5
Diffirence from ID and Class
Class selectors work in a similar way. The major difference is that IDs can only be applied once per page, while classes can be used as many times on a page as needed. If will use this cod , it work the same. Why guys? The HTML: <div> <p id="first">This is a paragraph</p> <p> This is the second paragraph. </p> </div> <p id="first"> This is not in the intro section</p> <p> The second paragraph is not in the intro section. </p> The CSS: #first {font-size: 200%;}
4 Respostas
+ 9
Take note that HTML is a markup language.
Unlike most programming languages, nothing stops you from digging yourself into a hole in HTML.
It obviously wrong to have duplicate global attribute (id) but the browser will still try its best to parse it. So please don't do it. 😉
+ 4
ID is used to get a specific tag item while class is for a group of tags.
Depending of your purposes you may prefer one or the other.
+ 3
this will be more troublesome when javascript access DOM
examples:
document.getElementById("first") //error occur
+ 1
the differents in specificity of selectors
https://developer.mozilla.org/uk/docs/Web/CSS/Specificity