Rickname Posted January 24, 2018 Share Posted January 24, 2018 I'm quite new to coding, and have big trouble understanding the logic in even the supposedly easiest languages to learn. However, what is the functional differences between .class and #id? Is there situations where only either of them can be used? I can't see any difference by reading the W3 pages about them (respectively https://www.w3schools.com/cssref/sel_class.asp and https://www.w3schools.com/cssref/sel_id.asp). Link to comment Share on other sites More sharing options...
dsonesuk Posted January 24, 2018 Share Posted January 24, 2018 id ref can be only applied to a single element on a page, a class reference can refer to multiple elements with same class reference on a page. Link to comment Share on other sites More sharing options...
Rickname Posted January 25, 2018 Author Share Posted January 25, 2018 So classes are more flexible ref than id. But what is special about id? I can't imaging why it exists if it only can do what classes can do, and that with narrower field of usage. Link to comment Share on other sites More sharing options...
dsonesuk Posted January 25, 2018 Share Posted January 25, 2018 (edited) For CSS you can target a specific singular id that refers to a specific area from a website layout ,that has multiple classes that are also used within other areas that each have a unique id. Then by referring to this id and then the class name as in '#idref .classname' I can change the styling of these classes, without affecting others elsewhere. For JavaScript you can do the same to manipulate specific elements within that id identifier element only . Simple example would be #header, #left, #right, #content, #left-aside, #right-aside, which specifically identify a specific area of your site, which you need to style and target individually. Edited January 25, 2018 by dsonesuk Link to comment Share on other sites More sharing options...
Rickname Posted January 26, 2018 Author Share Posted January 26, 2018 Thanks @dsonesuk! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now