+ 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%;}

11th Oct 2017, 4:53 AM
BraG.A
BraG.A - avatar
4 ответов
+ 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. 😉
11th Oct 2017, 5:49 AM
Zephyr Koo
Zephyr Koo - avatar
+ 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.
11th Oct 2017, 5:14 AM
Dapper Mink
Dapper Mink - avatar
+ 3
this will be more troublesome when javascript access DOM examples: document.getElementById("first") //error occur
11th Oct 2017, 5:15 AM
林偉雄
林偉雄 - avatar
+ 1
the differents in specificity of selectors https://developer.mozilla.org/uk/docs/Web/CSS/Specificity
12th Jan 2018, 11:25 AM
Vladislav Pomazan
Vladislav Pomazan - avatar