English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi am confused in using the

tag in html and css sheets. I want a webpage that has effectivly two colums one left navigation bar and the main right hand side for text and images. I have seen other pages that have the following
what does the class bit do that different from the id tag.
Till now i have just used
with id positioning each part by the margin 10px 10px..., its kinda messy but works. So is the class thing different better? any help ideas?

2007-08-27 04:44:46 · 3 answers · asked by pj2024 3 in Computers & Internet Programming & Design

3 answers

Class is different from id in that class identifies something that you can use more than once on a page. Id is more specific and carries more weight in the css "cascade" in that it is for an item that will be used once and only once. For example, if you have ONE AND ONLY ONE paragraph that's gonna have TIMES font and margin-left of 10ems and margin-right of 10ems and a color of blue and a border above it of green and a border below it of purple then you could give it an id of p#strange and in your web page place

what?



But if you want two such paragraphs on the same page, maybe one near the top and one near the bottom, you'd darned well better use a class! Like
p.strange { ... }

then

what?


in those two places

Also, if you have:
div#strange { color: purple; }
AND
p.strange { color: blue }

then you code

and

What?



...you might get surprised!

2007-08-27 04:57:00 · answer #1 · answered by fjpoblam 7 · 0 0

class refers to the type of the tag (in this case div), where id refers to any tag... for example:

has to have a div.one definition in css. This will only change that tag...
has to have #one in css. this means that any other tag that has id="one" can use this css definition. This way you can mix up you style definitions.
However, you can also use .one definiton in css, and then every html tag that has will import these style settings. But then again you can limit the usage of the class definiton to a single tag.
You can also use this:


with the corresponding div.one and div.two definitons in css. this way they eill have different styles... You can't do that with id. If you want to that with id you'll have to use different names...

Regards..

2007-08-27 11:58:48 · answer #2 · answered by jonycus 1 · 0 0

They can do pretty much the same thing, but generally you use id when you're only going to use it once on the whole page. You use class when you're going to use it more than once. It's really a semantics thing. id is there to denote that this is a unique thing, so it has its own id. class is there to denote that this follows the format of a bunch of things on that page.

2007-08-27 11:50:17 · answer #3 · answered by Jon G 4 · 0 0

fedest.com, questions and answers