Jump to content

Which Do You Recommend Or Use? Class Or Id


remrow
 Share

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...