...

View Full Version : Need CSS Help



shashgo
11-11-2002, 06:50 PM
Hi all,

What is the difference between
<p id=#347>Text</p>
and
<p class=347>Text</p>

cg9com
11-11-2002, 07:39 PM
i cut and pasted from this website, you should read more about it:
http://www.w3schools.com/css/css_syntax.asp

if you are using just a stylesheet to identify custom elements
just use class=""




.center {text-align: center}

In the code below both the h1 element and the p element have class="center". This means that both elements will follow the rules in the ".center" selector:

<h1 class="center">
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>



--------------------------------------------------------------------------------

The id Attribute
The id attribute can be defined in two ways. It can be defined to match all HTML elements with a particular id, or to match only one HTML element with a particular id.

<p id="intro">
This paragraph will be right-aligned.
</p>


In this example the id attribute will match all HTML elements with id="intro":

#intro
{
font-size:110%;
font-weight:bold;
color:#0000ff;
background-color:transparent
}


In this example the id attribute will match only p elements with id="intro":

p#intro
{
font-size:110%;
font-weight:bold;
color:#0000ff;
background-color:transparent
}

MCookie
11-11-2002, 07:52 PM
#347

Also, id selectors should not start with a number.

Motif Webs
11-12-2002, 05:06 AM
It is hard to understand the difference between using an ID as opposed to class. Some clearer explanations of a complex subject are at:

* http://css-discuss.incutio.com/?page=ClassesVsIds
* http://archives.hwg.org/hwg-techniques/002801c07a47$7dab0300$8400a8c0@WORKGROUP

However, I think the best explanation I've read comes from http://www.brainjar.com/css/using/default2.asp and says:
Class vs. ID
The ID attribute of an HTML tag is intended solely to provide a unique identifier. The CLASS attribute, however, was specifically designed to allow authors to assign styles to elements.

Strictly speaking, no two elements within a document (web page) can have the same ID. Anytime you add an ID attribute to a tag, its value should be different from that of any other element's ID on the page, even if they have different tag names. So a style rule with an ID selector can, at most, only apply to a single element on a page.

So why not just use an inline style instead of an ID selector in a style sheet? Well, you'll probably find it more convenient to keep all your style definitions in one place, rather than scattered throughout the document. And, if the style sheet is external, it can be shared by multiple pages.

Note that if you do specify a tag name on a ID selector (e.g., h1#mainTitle instead of #mainTitle) the tag name and ID must match the element in order for the style to be applied.
The class selector, on the other hand, can match several elements on a page, even elements with different tag names. And, a tag can have more than one class (by specifying a list of class names separated by spaces). For example, given the following rules and HTML

h3.warning { color: red }
.highlight { background-color: yellow }

...

<h3 class="warning highlight">Danger</h3>

<h4 class="warning highlight">Proceed with Caution</h4>
The H3 tag would appear in red text, but the H4 tag would not. Both would have a yellow background however.

Hope this helps.

Neil

whammy
11-12-2002, 11:43 PM
...and that is absolutely correct. If you use id instead of class in more than one spot, then when you try to validate your XHTML you will find to your dismay that the validator tells you exactly what brainjar's site does. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum