There’s a hierarchy to tags, ids and classes (in that order). Within the context of the “Cascade” part of CSS an id style can, in many circumstances (eg, with some FW Action-generated code), be difficult to near impossible to override with another style because it’s given greater importance in the larger scheme. This can lead to the use of overly specific selectors just to override an id style, a practice which is probably best kept in check when possible. This is all undesirable. Some basement dwellers argue that id styles should not be used at all. I think that’s a bit extreme, I say use with care. Stick with classes, they play more nicely. If you ever start writing your own CSS you will quickly understand why id styles, when used indiscriminately, can be a pain in the ass.
I know the question was probably referring to CSS but don’t forget the use of classes and id’s on page elements when using jQuery for example, this is something that people dabble with in Freeway and is also affected through the use of classes and id’s.
Using a * class * to access jQuery code over a ‘range of page elements’ or an * id * to access ‘one page element’ and manipulate those elements through jQuery. Having more than one element using an * id * of the same name can cause issues as for example: If you where to use jQuery to perform some action on page elements and doing that using an element * id * on those several elements then only the first would function properly while accessing several page elements through the use of a * class * would have all those elements perform the action that jQuery was telling them to.
Working on this principal: If there where more than one page element needed to fire a jQuery event or a jQuery event where to be performed on more than 1 element the use of a * class * to connect to that element would be better used while if that jQuery event where to be performed by accessing only one element on the page or performed on one element an * id * would be better used.
How do I decide if I where to use a class or id on a page, if I needed to connect/access more than one page element I would use a class, if I needed to connect/access only one page element I would use the an id.
HTH
On Nov 23, 2013, at 6:2 AM, Todd wrote:
Is this a pop quiz?
There’s a hierarchy to tags, ids and classes (in that order). Within the context of the “Cascade” part of CSS an id style can, in many circumstances (eg, with some FW Action-generated code), be difficult to near impossible to override with another style because it’s given greater importance in the larger scheme. This can lead to the use of overly specific selectors just to override an id style, a practice which is probably best kept in check when possible. This is all undesirable. Some basement dwellers argue that id styles should not be used at all. I think that’s a bit extreme, I say use with care. Stick with classes, they play more nicely. If you ever start writing your own CSS you will quickly understand why id styles, when used indiscriminately, can be a pain in the ass.
I think that for me the most important feature is that classes are reusable ie you can have many items on the same page with the same class but IDs are unique to one item.
So #mystyle {property:value;} will only ever apply to the item with the ID of mystyle
Ernie posted a good explanation of CSS related problems with FW generated ids but it’s also a useful read when trying to understand how ids can be problematic and why classes are generally a better option.
Ernie? Can you post the link to that post? I couldn’t find it on FWT.
Ernie? Can you post the link to that post? I couldn’t find it on FWT.
Are you sure it wasn’t Walter? My bailiwick has been CSS Specificity…
though surely I find many instances where I wish Freeway Pro would let me
choose where and how an item’s CSS was written.
Imagine if you had a checkbox for div’s on whether you wanted the
dimensions and padding to be written as id style #mydiv {property:value;}
or as .style16 {property:value;} or choose an existing class style…
Currently, there are a couple actions I think which strip out the id, then
you can easily apply a class style… though I think it would be better if
the div could keep the id just for sake of other possible uses.
Specificity is part of the CSS Cascade, and is a formula for determining
the order in which styles are applied - so if one style makes something red
and another style makes it blue, CSS has a way to know which style rule
applies.
Yeah, that’s it, specificity. I thought you gave a good use-case scenario and insight into how ids can in sometimes be CSS speed bumps. It might give a slightly different perspective to Kelly’s question of why to use one type of style over another (class vs. id vs. tag).
Well, I’m not sure where all that went to, especially after Softpress
changed some of what was giving me grief… specifically the order in which
stylesheets get written in the head.
Here is an article on the subject which I never finished, so everyone just
keep in mind that this was incomplete AND Softpress made some of the
changes I asked for. That said, I did spend a lot of time trying to layout
how CSS Specificity works in the plainest language possible… with graphs. http://cssway.thebigerns.com/special/master-item-styles/