|
|
|
|
![]() ![]() |
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? |
|
|
|
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. |
|
|
|
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.
|
|
|
|
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 |
|
|
|
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: [MODERATOR] Posts: 3,882 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
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 |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 26th July 2008 - 07:08 AM |