Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Class Vs. Id?


7 replies to this topic

#1 KansukeKojima

    Your local Christian Metalhead

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 567 posts
  • Gender:Male
  • Location:Alberta, Canada
  • Interests:Theology, Christianity, Metal (Black Metal, Death Metal, Folk Metal, etc.), art, other stuff...
  • myCENT:29.32

Posted 14 February 2008 - 04:09 PM

#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?

#2 Forbez

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 662 posts

Posted 14 February 2008 - 04:24 PM

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.

#3 KansukeKojima

    Your local Christian Metalhead

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 567 posts
  • Gender:Male
  • Location:Alberta, Canada
  • Interests:Theology, Christianity, Metal (Black Metal, Death Metal, Folk Metal, etc.), art, other stuff...
  • myCENT:29.32

Posted 14 February 2008 - 04:50 PM

ahh... ok thank you.

#4 sonesay

    |||[ n00b King ]|||

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 958 posts
  • Gender:Male
  • Location:Auckland
  • myCENT:68.27

Posted 14 February 2008 - 06:11 PM

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.

Edited by sonesay, 14 February 2008 - 06:14 PM.


#5 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,040 posts
  • Gender:Not Telling
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • myCENT:81.07
  • Spam Patrol

Posted 14 February 2008 - 07:32 PM

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...tml#specificity

#6 martinnovoty

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 11 posts

Posted 01 August 2008 - 02:45 PM

View PostForbez, on Feb 14 2008, 06:24 PM, said:

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.

That's not the true, you can do same with id's.

BRs,
M.

#7 Pinkeboo

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 12 posts

Posted 04 August 2008 - 04:13 AM

id tags in HTML (<div id=”header”>) are tags which should only be used once per web page. Generally, you want to use an ID to denote the page structure, so you might have id’s for a web page of “header”, “content”, “sidebar” and “footer”, because you’re not going to have two headers or two footers for any one webpage.

Class: Unlike ID tags, class tags can be used multiple times. This is great when you want different parts of the design to look the same.

#8 KingSingh

    Newbie

  • Kontributors
  • Pip
  • 7 posts

Posted 04 August 2008 - 02:19 PM

Following on from what Pinkeboo said above, id's are used for thing's like header's, footer's, sidebar's etc. and are like this in The CSS:
#idname { property: value; text-align: right }
ID's are shown with HTML usually with div tags like this:
<div id="idname">Content content content etc</div>
Classes can be used several times and a commonly used style of classes is to align. For example, the CSS to centre align anything
.center { text-align: center; }
and the HTML would be like this:
<div class="right"></div>
If you want the same class for different HTML tags, you can do this:
p.right { property:value; }
div.right { different stuff: from above; }
and
<p class="right">content</p>
<div class="right">Differently styled right class</div>

I hope you have found this useful. :)

Edited by KingSingh, 04 August 2008 - 02:21 PM.





Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users