Question: When is a CSS Class not a CSS Class?
Answer: When it's a unique identifier.
Check out this class attribute generate by my beloved Wordpress' upload feature:
class="alignleft size-medium wp-image-4590"
See anything suspicious? I sure do. wp-image-4590 is a unique identifier being passed off as a class. Why? I actually have no clue as I'm not privy to the thought process behind that particular piece of code
What I do know is pretty much demands to be an ID. When I teach this stuff to people, I say "If it's unique, meaning there will ever only be one of them, make it an ID. If there's more than one or it's a general descriptor, make it a class." So I look at that code block every time I upload an image and I frown. Then I blow away the whole class attribute away, since I use none of them.
This is just splitting hairs, I know. Using a class like that is basically harmless. But, truth be told, splitting hairs helps me solidify my ideas about the way these things should work. That, in turn helps me improve the way my crew and I do our thing. So? Hairs I split and everyone is happier.
I'm just doing my small part to make the web a better place one nitpicky, semantic post at a time.
Tom Says:
The one thing I can think of is that they are anticipating that the image might be used more than once on a page. In which case, an ID wouldn't work.
Logic could be inserted to decide if the element only appears once on a page or not and give an ID or class accordingly, but for simplicity's sake, it makes more sense to keep it as a class.
Posted: June 15th, 2008 at 11:10 am
rob Says:
I guess the question is, how often is one image inserted into a Wordpress post multiple times? I bet it doesn't happen all that often. In which case WP is coding for a problem that isn't all that much of a problem.
Wordpress isn't the only one guilty of this, of course, Drupal used to (and might still) have unique class names for all of their menu items-
<li class="last menu-1-2-2">
I guess the same argument could me made there, although I liked it even less in Drupal
Posted: June 15th, 2008 at 11:47 am