Wednesday, January 9, 2013

Styling By IDs: Case In Point

There has been some argument in the web development community about styling HTML by IDs. Arguments against styling by ID include specificity (IDs are hard to override), and, more importantly, code reuse.

If you know anything about HTML, you probably know that IDs are supposed to be unique. This means that there can only be one of any particular ID per page. As the argument goes, if you absolutely know that you’re only going to have one of a particular design element on a page, then go ahead and use an ID.

But you don’t know that.

No, really, you don’t know that.

I was recently modifying a “view shopping cart” page. When it was built, it was done so under the assumption that you would only have one list of items in your cart. This is, I think, a valid assumption.

However, I’m now adding something that really really wants to look like a list of items in your cart. Since it was styled with IDs, though, that process becomes more complex. I have to change the HTML as well as the CSS, instead of just changing the HTML.

No comments:

Post a Comment