Previous Message
Next Message

A basic question

Sent by Jukka K. Korpela on 1 March 2005 10:10


On Tue, 1 Mar 2005, Bob McClelland wrote:

> I've noticed that, quite often, some folk use classes of the type:
>
>                 div#links {etc . . .}
>
> whereas I would just use :
>
>                 #links {etc . . .}
>
> So, seeing as some of those who do this are pretty darn good at it, I
> presume there is a reason for the 'div'?

The short answer is that the two are completely equivalent (assuming that
"links" appears as the value of an id attribute in a <div> element),
except that the former has higher specificity. Specificity only matters if
there are several rules that apply to an element (in the same stylesheet
or in another stylesheet).

Mostly it's probably just a matter of habit. And maybe some people think
that div#links looks a bit more clear intuitively (though this point
is more relevant when selectors like .foo versu div.foo are used - the
lone "." before a name can be rather unnoticeable).

Using #links is a bit more flexible, since if later decide to change the
markup element from, say, <div> to <p> or <ul>, you don't need to change
the stylesheet just because of the markup change. (However since different
elements have default rendering, you should probably still check
whether the stylesheet needs some changes.)

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/

______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread:

Possibly related: