Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Class Vs. Id?
KansukeKojima
post Feb 14 2008, 04:09 PM
Post #1


Privileged Member
*********

Group: [HOSTED]
Posts: 525
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



CODE
#random_div {
random: random;
random: random;
}

.random_div {
random: random;
random: random;
}


Ok... well.. above we have a id (the first one) and then the second one is a class. Could anyone please explain to me what the difference between the two is? And is one any better?
Go to the top of the page
 
+Quote Post
Forbez
post Feb 14 2008, 04:24 PM
Post #2


Privileged Member
*********

Group: [HOSTED]
Posts: 572
Joined: 13-December 06
Member No.: 35,271



Class can change like the header tag and other tags like that. So you could have

.random_div h1 {
random: random;
random: random;
}
Anything within the div which is inbetween the <h1> tag will change according to what you put. Id doesn't do this I believe. Use a mixture of both to get a better effect.
Go to the top of the page
 
+Quote Post
KansukeKojima
post Feb 14 2008, 04:50 PM
Post #3


Privileged Member
*********

Group: [HOSTED]
Posts: 525
Joined: 13-October 06
From: Alberta, Canada
Member No.: 31,584



ahh... ok thank you.
Go to the top of the page
 
+Quote Post
sonesay
post Feb 14 2008, 06:11 PM
Post #4


|||[ n00b King ]|||
*********

Group: [HOSTED]
Posts: 643
Joined: 20-June 07
From: Auckland
Member No.: 45,102



ID's are used when you need define a single element and apply CSS to that element only or you need an easy way for javascript to get to it.


Class are used when you have 2 or more elments you need consistent styling.
e.g All the the content sections need to be the same style(you may have several division blocks of content).

I cant think of any other reasons why you would them at this stage.

This post has been edited by sonesay: Feb 14 2008, 06:14 PM
Go to the top of the page
 
+Quote Post
jlhaslip
post Feb 14 2008, 07:32 PM
Post #5


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



As stated above, ID's should be used when you have one (and only one) Element on the page that you want to style.
Classes can occur once or many times on the same page.

Id's are more 'specific' when the styling is parsed, so the styles for an ID will override a class if there is a conflict in the Cascade.

Check this link: http://www.w3.org/TR/CSS21/cascade.html#specificity
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. What A Hero Means To Me - An Essay Written For English Class.(1)
  2. C++ Class(6)
  3. Advice On Impressing Someone In My Class(6)
  4. English Class Speech(7)
  5. Adding Accessibility Features To Your Pages(0)
  6. New Class Of Attack Targets Embedded Devices(2)
  7. What Are Parametric Equations?(2)
  8. My Life After High School(2)
  9. What's Your Favorite Class/job?(4)
  10. A Girl In My English Class Is Simply Amazing...(10)
  11. Php Education Class (first Code)(0)
  12. What Is Your Idea About My Php Class?(4)
  13. Need Help With My Speech Class(2)
  14. Eclipse Exporting .jar Files(4)
  15. Php Template Class I Started(1)
  1. Final Spec's Of My Computer Build For My Hardware Class(11)
  2. Alright, I'm Taking Computer Programming As A Class In School.(6)
  3. Do You Ever Skip Class?(58)
  4. The Story Of The Student Who Failed Writing Class(1)
  5. Php Email Validation(1)
  6. Count Number Of Div's By A Class Name(3)
  7. P.e. Class(2)
  8. Marijuana(3)
  9. History Class Project- Prohibition(0)
  10. Law And You Class - Competion(0)
  11. Css Multiclassing(2)
  12. Much Fun In Math Class(8)
  13. My Spy Suggestions For Team Fortress 2 Next Update S(2)


 



- Lo-Fi Version Time is now: 26th July 2008 - 07:08 AM