KansukeKojima 0 Report post Posted February 14, 2008 #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? Share this post Link to post Share on other sites
Forbez 0 Report post Posted February 14, 2008 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. Share this post Link to post Share on other sites
KansukeKojima 0 Report post Posted February 14, 2008 ahh... ok thank you. Share this post Link to post Share on other sites
sonesay 7 Report post Posted February 14, 2008 (edited) 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 February 14, 2008 by sonesay (see edit history) Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted February 14, 2008 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%23specificity Share this post Link to post Share on other sites
martinnovoty 0 Report post Posted August 1, 2008 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. Share this post Link to post Share on other sites
Pinkeboo 0 Report post Posted August 4, 2008 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. Share this post Link to post Share on other sites
KingSingh 0 Report post Posted August 4, 2008 (edited) 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 August 4, 2008 by KingSingh (see edit history) Share this post Link to post Share on other sites