ID & Class
Hi Everybody can someone please tell me that what is difference between ID and Class in css..................... Thanks in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ankit NandekarPosted May 4, 2011, 5:56 AM
ID's are unique
- Each element can have only one ID
- Each page can have only one element with that ID
your code will not pass validation if you use the same ID on more than one element. Validation should be important to all of us, so that alone is a big one.Classes are NOT unique
- You can use the same class on multiple elements.
- You can use multiple classes on the same element.
Any styling information that needs to be applied to multiple objects on a page should be done with a class. Take for example a page with multiple "Maindiv":For more details visit this link
http://www.soft32.com/download_112.html
Mpholo LeboeaPosted May 4, 2011, 4:49 AM
ID
ID is the only identity that can be used on the web page to uniquely identify a single element.
ID can only be assign/used once to identify element on a page.
Class
Class can identify a group of elements on the web page.
Class can appear/be assigned to more than one element on the web page.
They can both be used in stylesheets to style you pages and Javascript/JQuery to refer to element(s).
Amit ChoudharyPosted May 3, 2011, 11:26 AM
When you want to apply unique css style to particular HTML element then we use ID as it is the unique for all elements on any HTML page.
Basically used with "#" for e.g. #Div1{ border: solid 1px gray;}
if you want to use the same css style on different elements then we use Class.
Class is defined with "." for e.g. .CommonDiv{border:none; color:red;}
hope this make sense to you.
Thanks