/    Sign up×
Community /Pin to ProfileBookmark

Can someone me tell me please what exactly is the difference between a class and an id and when i should use which.

Thanks

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@Rick_BullDec 06.2002 — Use an ID when you want to apply style properties to one element only, use a class when you need it to be reusable, e.g.:

<i>
</i>CSS:
#menu { /*MENU object only*/
position:absolute;
top:0px;
left:0px;
}
.center { /*For centering objects*/
text-align:center;
}

HTML:
&lt;div id="menu"&gt;
&lt;h2&gt;Blah&lt;/h2&gt;
&lt;p class="center"&gt;Blah&lt;/p&gt;
&lt;/div&gt;
&lt;p class="center"&gt;More blahs&lt;/p&gt;
Copy linkTweet thisAlerts:
@telconstar99Dec 09.2002 — IDs are useful if you wish to incorporate javascript as well. Check this explanation out:

http://www.htmlgoodies.com/beyond/classid.html
Copy linkTweet thisAlerts:
@Robert_WellockDec 09.2002 — The "id" is a unique identifier and can only appear once within an XHTML document, the thing which makes attributes of type "id" special is that no two such attributes can have the same value; whatever the document language.

Joe obviously doesn't completely understand the full functionally of the "id" he seems to think it doesn't do anything different than class within HTML which is wrong, you'd probably notice that it you tried a completely table-less design using CSS-P :p.
Copy linkTweet thisAlerts:
@RazvanBladeJul 01.2011 — hello, Im new around here and trying to understand css...

so in a website if i have let
s say 10 properties that i want to give to more than 1 object, i can put them all in 1 class and call that class whenever i want those properties?


exactly, i have a right div=right bar, and inside i want 5 more div tags, each different, but they all have in common some properties. can i make then ID`s and inside each of them also call the same class?
×

Success!

Help @Max_Power2 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.25,
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,
)...