/    Sign up×
Community /Pin to ProfileBookmark

Why use div#ID instead of just #ID?

I’m curious why some ID or CLASS tags in stylesheets have a div before them? Does that mean it’s just a class or id within another div?

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@ryanbutlerJul 25.2007 — I sometimes do it so that I know what specific element I'm styling. If I have multiple DIV's in a layout, its helpful to know which specific element I'm styling. Plus, it does add the greatest level of specificity you can have, because if there's a potential conflict than nothing will supersede it.

Hope this helps.
Copy linkTweet thisAlerts:
@felgallJul 25.2007 — With classes it specifies which particular element type to apply the style to as the same class can be applied to many different elements and they don't all need to be the same type.

For an id it is effectively a commment to remind the writer what type of element they attached the id to with the added advantage that, since the style will only be applied at all if the correct element type is specified, you know that the comment must be correct.
Copy linkTweet thisAlerts:
@ray326Jul 26.2007 — Also the level of specificity. div#id is more specific than #id and that can determine whether an element is selected or whether the style of another selector will override it. I believe Eric Meyer has an article about that on his site but it might be Cederholm.
×

Success!

Help @askfritz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...