Jump to content

Which Do You Recommend Or Use? Class Or Id


remrow

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...