|
Nancy -> RE: class vs. id (3/12/2004 14:55:28)
|
quote:
ORIGINAL: lilblackgirl quote:
A class is a set of styles that can be applied many times over on a page. An id is a set of styles that can be applied just once to only one unique element on a page. A div (short for division) is a box on the page. Divs can be styled or unstyled. They're just containers. They are typically used to hold other page elements. So, hiearchically, a div would reference something at the highest level (whatever you put inside that invisible box), a class would be specific to something like content or links that you wanted to display in a way that may be different from the rest of the page and an id would be at the bottom of the food chain specifying a style for something very specific on a page (to only be used once)? Did i get that right? Actually no. But some of it is right. *S* A div is already an html tag - just the same as <p> or <table> or any number of others you're already familiar with. Class, and ID refer to ways to (hmmmmm hope gorilla doesn't blast me too bad for my simplification of this) attach or apply a style to an html tag. So in previous times, hereafter referred to as BSS (before stylesheets) you would put certain attributes into the opening html tag to further define information, such as table padding or cell spacing etc, or alignment, or whatever. Now that information goes into a stylesheet ( after stylesheets A*SS - just realized my abbreviation for after isn't going to work :( ) In other words, you are eliminating the html attributes, and putting that information into a stylesheet. And in order to give instruction to the html tag as to how it is supposed to look, you give it a class or an ID. There are many reasons to use both class and ID. I like to use information in the ID that is unique, since the ID will only be used once. For information that will be used possibly more than once, that information can go into a class. For example, a div can be positioned on a page. So that information would be unique - thus it would go into an ID. Further information such as link color etc, which might be used several places, could be put into a class. Information that might apply always to a page would be put with the selector for a rule, such as font family or page background image or color, which could go into the <body> selector of a CSS rule. Hope the above makes a little clarification for you. Nancy
|
|
|
|