Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question on CSS

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
When working with CSS. what is the difference between these two and how do you use them

.maintext
#maintext

Thanks.

 
.maintext is a class

#maintext is an element id

You can define a class, or set of CSS rules, and apply this set to anything on your page. You can use the same class multiple times on each page.
e.g.
Code:
<p class="myClass">Blah blah</p>
<p class="myClass">More Blah blah</p>
<p class="myClass">Yet more Blah blah</p>

Conversely, you can only refer to a named element once per page. A named element can also be referred to and modified with JavaScript.
Named elements are useful for defining blocks of content.
You can then define rules for standard HTML tags based on where they appear in your document.
i.e. <li>tags in your main content display differently to <li> in your left column.

The benefit of this approach is that your code is much tidier as you do not have classes declared all over the place.

Personally I favour defining CSS ruled for standard HTML elements, and rules for named elements as per my page structure. Such as #content or #navigation.


 
So your saying if I have something like this

#contentheader
#maintext

I can use it like this?

<div id="contentheader">Whatever here </div>
<div id="maintext">Whatever here </div>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top