remrow Posted February 26, 2010 Share Posted February 26, 2010 What is the Difference between Class and ID?We can use the css styles from both of them but why are they different?? Link to comment Share on other sites More sharing options...
Synook Posted February 26, 2010 Share Posted February 26, 2010 IDs can only be used once in a document, and are therefore useful for other things such as for semantic purposes and for identification when scripting. Classes can be used multiple times. Link to comment Share on other sites More sharing options...
jeffman Posted February 26, 2010 Share Posted February 26, 2010 Use an id to select a unique item. Perhaps your page has exactly one div called "wrapper" that contains all the other page elements. Most designers would use an id selector.Often you define a class of elements, but one element of the class needs to have something different. Like maybe your header element and footer element have 8-10 CSS properties in common. Define them as a class. Now imagine the footer has a different height. That one different property can be defined using an id selector. The footer tag would reference both the id and the class. Link to comment Share on other sites More sharing options...
Synook Posted February 27, 2010 Share Posted February 27, 2010 You can also reference multiple classes to apply to an element simply by space-delimiting them: <element class="class1 class2 class3"> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.