BIRT 3.7
Written by: Michael Williams
Featured Refcardz: Top Refcardz:
  1. Scrum
  2. Apache Maven 2
  3. Essential MySQL
  4. Node.js
  5. Groovy
  1. jQuery Selectors
  2. Ajax
  3. Java
  4. Spring Config.
  5. Java Concurrency

Link Details

Link 191745 thumbnail
User 388824 avatar

By a0
via f055.net
Published: Jun 10 2009 / 07:08

In CSS, you can assign styles to elements in 3 ways: either by a direct reference to an HTML tag, or by a class attribute, or finally, by the id attribute. Each of these approaches has it’s pros and cons, but in this article, I’ll highlight why you should avoid using styling by #id. In fact, you shouldn’t base your style design on id attributes at all.
  • 11
  • 23
  • 2465
  • 4

Comments

Add your comment
User 297517 avatar

WebmasterNeal replied ago:

0 votes Vote down Vote up Reply

The problem is, IDs are a less expensive selector in Javascript & CSS because IDs are as specific as you can get. They best suited for side-wide structural elements like content, sidebars & navigation.

User 388824 avatar

Marek Foss replied ago:

1 votes Vote down Vote up Reply

What is cheap at the beginning gets really expensive with time. Believe me, their specification is what makes them expensive in the long run.

User 294215 avatar

cletus replied ago:

0 votes Vote down Vote up Reply

Obviously this person has never coded or maintained even a moderately sized site. Sorry but just because your website gets 150 hits a month doesn't mean you can speak with authority on Javascript, HTML or CSS.

User 388824 avatar

Marek Foss replied ago:

2 votes Vote down Vote up Reply

If you all wish to make your lives harder then I won't stop you. And if the only argument you can throw is a personal insult, then that only describes you. My post is my opinion and I'm going to stick to it. I'm not holding a gun against your head and telling you I know everything and you must do as I say.

I'm just saying flexibility is the crucial element in todays design. And IDs are certainly not a friendly part of it, in the long run. Don't be quick in judgment and short-sighted, please.

User 261337 avatar

John Rockefeller replied ago:

0 votes Vote down Vote up Reply

I've been saying this for years, as well. Other than referencing the element directly and easily in Javascript, ids should be abandoned for classes.

User 239201 avatar

amphi replied ago:

0 votes Vote down Vote up Reply

I only use ids for layout-regions and targets. Just like any other sane person.

User 332859 avatar

PureForm replied ago:

0 votes Vote down Vote up Reply

I completely agree... I've always stuck to: class = css, id = dom segregation ... though I will deviate from time to time if they would end up sharing the same string, like > but even that's extremely rare for me...

Good to know I'm not the only one with this ideology :-)

User 332859 avatar

PureForm replied ago:

0 votes Vote down Vote up Reply

Whoops, it stripped the html... let me try another way:
[div id="something1" class="something1"] --> [div id="something1"]

But I only do this when the div it's self will be manipulated via the DOM

User 272665 avatar

zalun replied ago:

0 votes Vote down Vote up Reply

Disagree.
Think of #id and .class as of user and group.
One can use #id for identification and .class for grouped parameters.
Anyway, I commented longer on the blog

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.