[/cc]

ID’s are designed to be unique, but there are times we don’t, and it doesn’t’ seem to matter.

When it comes to using ID’s for styling, I’ve heard philosophy both ways:

Here are the facts, so you can decide how you want to handle ID’s and classes:

A good rule of thumb is this:

I hope this clears the air, as you can begin to make educated decisions.

Whitespace Doesn’t Matter

[cc lang=”css”]div{color:red}[/cc]

This means the same as:

[cc lang=”css”]div {
color : red

}[/cc]

Of course, these are not the same;

[cc lang=”css”]ulli { }[/cc]

[cc lang=”css”]ul li { }[/cc]

So, what does this mean?

Find what you’re the most comfortable doing! There are multiple ways to layout your CSS. Some like one line, some like to break it down. Whatever makes the most sense to you.

Semicolons Matter

You may have noticed that in the example above, there is a missing semicolon.

It’s allowed only when it is the last property listed in a group!

I make a habit of always using a semicolon, that way when I’m making edits or add a property, it’s already taken care of.

This, for example, won’t work:

[cc lang=”css”]div {
-webkit-border-radius: 10px
-moz-border-radius: 10px
border-radius: 10px
}[/cc]

No semicolons = FAIL

If you are tooling around in someone elses’ stylesheet, this is something to keep in mind, since it is a small detail that can wreck your design.

I hope these were helpful, and as I said yesterday, share with us a basic CSS concept that was a major “ah-ha” moment for you.

[via CSS Tricks | Image via Squirrelly Mae]

Eric Dye

Support Lead at Valet, and Proprietor of DYECASTING. Human by day, gamer at night, lover of coffee, and all things spicy.

Level up your inbox.

Free resources, top posts, and more!

Reader Interactions

There are 3 comments already... Come join us!

  1. Chase Livingston says

    Great tips Eric! I had never heard a definitive answer as to why one would use an id or a class in a certain situation. Makes much more sense now!

Trackbacks

Speak your mind...

Your email address will not be published. Required fields are marked *