navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Class VS. ID

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> Cascading Style Sheets >> Class VS. ID
Page: [1]
 
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
Class VS. ID - 6/10/2003 15:48:53   
I' ve always used <div class=" xyz" > rather than <div id=" xyz" > for everything in my CSS...

Anyone have an opinion (or factual data as the case may be...) on one vs. the other?

Just for curiosity sake... and in case I get to learn something new... :)

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)
Gil

 

Posts: 7533
From: North Carolina, USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 16:45:37   
Earlier versions of Netscape (4.xx) had a problem w/ ID, but I think they fixed it now

Also:
ID Selectors

This selector was designed to match the value of the HTML ' ID' attribute, but SGML/XML both allow the ID attribute value type. With this type of attribute, each element in a document can have a uniquely referenceable label. This Selector syntax precedes the attribute value with a pound symbol (" #" .) An element name or Universal Selector may be used in front of the ID Selector, but it is not necessary. The effect of this selector can also be achieved using an Attribute Value Selector, but this form of Selector has a higher cascading precedence.


_____________________________

Gil Harvey, 1947-2004

(in reply to bobby)
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 17:05:07   
Maybe that' s why I started with CLASS in the first place..?

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)

(in reply to bobby)
Gil

 

Posts: 7533
From: North Carolina, USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 17:10:25   
Probably - I' ve always used class for that reason - but ID is more powerful when used with XML - so I guess I' ll need to learn a little more before jumping into XLS:)

_____________________________

Gil Harvey, 1947-2004

(in reply to bobby)
Spooky

 

Posts: 26597
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Class VS. ID - 6/10/2003 17:28:05   
The only thing with ID, is it should be unique on the page.

http://www.w3.org/TR/REC-CSS1#id-as-selector

Pageoneresults had a good example of one use with his css based menuscript in this forum.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bobby)
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 17:42:51   
Aha... so while Class=" x" gives a lot of control (I could use p class=" x" and div class=" x" on the same page)

id=" x" would grant better control via inheritance, but would have to be unique to a single element... either <p> or <div> but not both...

in other words... six of one, half-dozen of the other...

:)

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)

(in reply to bobby)
Gil

 

Posts: 7533
From: North Carolina, USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 17:50:00   
Also you can assign more than one class to the same element.

_____________________________

Gil Harvey, 1947-2004

(in reply to bobby)
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 18:03:56   
Oooooh... I' ve never tried that...

:)

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)

(in reply to bobby)
abbeyvet

 

Posts: 5095
From: Kilkenny Ireland
Status: offline

 
RE: Class VS. ID - 6/10/2003 19:05:21   
quote:

Also you can assign more than one class to the same element.


That is the sweetest, sweetest thing! Pageoneresults posted this a little while back and it was news to me to - and on that very day I found a use for it!

Here is how I used it in case it is useful to anyone.

I have links, on the left of a page in a nav bar, in the form of an unordered list. The link style specifies a different list-style-image depending on the link pseudo class, so that on hover the image before each item changes.

MMMM. I thought. Wouldn' t it be nice to have the list image change to mark which page the user was on, sort of a location indicator? But I still want the navigation in an include page, for convenience.

So, I used two classes in each link eg

<a href=" index.html" class=" leftnav home" >Home</a>
<a href=" about.html" class=" leftnav about" >About</a>
<a href=" contact.html" class=" leftnav contact" >Contact</a>

etc etc

Then I put an embedded stylesheet in each page, so that on say the home page it includes this:

a.home:visited {list-style-type:url(/images/layout/indicator.gif);}

on the about page this:

a.about:visited {list-style-type:url(/images/layout/indicator.gif);}

Now, by definition the page you are on is visited. So by just altering the page name in the embedded stylesheet the page you are on is indicated by a different image in the navigation bar.

I did the same in fact for the section the page was in, so that the bg color on the top nav bar changes, again as a location indicator.

Actually I then complicated, or simplified it depending on your view, by using PHP.

I put the entire header in an include page - that is everything from the <doc type... though </head><body> to the start of the content.

Then on each page I define the variables for the page:

<?php 
// Enter the title of the page
$title = " Some title" ; 
//enter the name of the section
$sectionid = " main" ;
//enter the name of the page
$pageid = " home" ;
//Enter Keywords for this page
$keywords = " keyword, keyword, keyword" ; 
//Enter description for this page
$description = " Write a page description here" ; 
//DO NOT EDIT
include($DOCUMENT_ROOT . " /includes/header.txt" );
?>


Then call the variables in the included header, which looks like this:

<!doctype HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN"  " http://www.w3.org/TR/REC-html40/loose.dtd" >

<html>
<head>
<title><?php echo " $title" ; ?></title>
<meta name=" keywords"  content=" <?php echo " $keywords" ; ?>" >
<meta name=" description"  content=" <?php echo " $description" ; ?>" >

<link rel=" stylesheet"  href=" /idnn.css"  type=" text/css" > 
<style type=" text/css" > @import url(/id.css);</style>

<style type=" text/css" >
a.<?php echo " $sectionid" ; ?> {background-color:#ffa081;}
a.<?php echo " $pageid" ; ?>:visited{list-style-image:url(/images/layout/indicator.gif);}
</style>

<SCRIPT LANGUAGE=" JavaScript"  SRC=" /global.js"  TYPE=" text/javascript" ></SCRIPT>
</head> 

<body>
<div class=" body" >



Because the footer is included also, it ends up being that each page is just content and a few variables, but boy can you make those variables work with the stylesheet!

I am sure you can so the same in ASP - I just know nothing about ASP.

Sorry for rambling - but I was so pleased with this setup, and so happy the P1r posted the thing about the two classes just as I was pondering how to do it - that I thought it might be useful to someone elese.

I cannot show you the site, its for a product that won' t be launched until next week, but I will then if anyone is interested in seeing it in action.

< Message edited by abbeyvet -- 6/10/2003 7:09:48 PM >


_____________________________

Katherine

:: InKK Design :: InKK Domains

(in reply to bobby)
pageoneresults

 

Posts: 1001
From: Orange, CA USA
Status: offline

 
RE: Class VS. ID - 6/10/2003 21:50:11   
[url=" http://www.webmasterworld.com/forum21/2932.htm" ]papabaer on ids[/url]

Search for that username papabaer at Google and look at some of his stuff. This guy is way beyond any CSS person that I' ve read about or who are classified as CSS Gurus. papabaer is well known at WebmasterWorld. I don' t think there has ever been a topic he was involved with that did not get solved. The man is a CSS Genius, beyond the Guru title.

Katherine, you go girl! I actually picked up that tip from my normal stomping grounds and brought it over here for all to enjoy.

_____________________________

SEO Consultants Directory
Find Search Engine Marketing Companies

(in reply to bobby)
gorilla

 

Posts: 2974
From: Denmark
Status: offline

 
RE: Class VS. ID - 6/11/2003 7:52:46   
quote:

ORIGINAL: bobby

Oooooh... I' ve never tried that...

:)


Karsten sits here in Copenhagen giggling at the thought of all the fun bobby is about to have. YOu' ll be AMAZED and THRILLED (sorry for shouting *g*) at the things you can do.


quote:

Also you can assign more than one class to the same element.


One tip - I' ve found better to use letters rather than numbers in my nomenclature for classes. a, b, c, etc rather long descriptive names. Also some browsers (I don' t have my notes with me so can' t give V Numbers opera some version was one .... sometimes gave me problems when I used numbers.)

OH BTW congratulations on your new baby.

Karsten

_____________________________

Mháircaish

Signature self-censored to protect the sensibilities of the thin-skinned :).

May we never confuse honest dissent with disloyal subversion. – Dwight D. Eisenhower



(in reply to bobby)
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Class VS. ID - 6/11/2003 10:42:17   
Thanks Karsten!

He' s taking away from my computer time :)

:)

I used to use class=" a" or class=" alpha" just to keep it generic... also will use class=" white" if it makes lots of sense...

Lately I' ve been using funky names and nonsensical terms. class=" flogsnarf" for example...

It makes typing web-code more fun (I do the same for ASP variables) and anyone who sees the page code is gonna roll their eyes and furrow their brow in wonder...
:)

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)

(in reply to bobby)
Gil

 

Posts: 7533
From: North Carolina, USA
Status: offline

 
RE: Class VS. ID - 6/11/2003 10:56:33   
quote:

anyone who sees the page code is gonna roll their eyes and furrow their brow in wonder...


Sounds like all of my code :)

_____________________________

Gil Harvey, 1947-2004

(in reply to bobby)
pageoneresults

 

Posts: 1001
From: Orange, CA USA
Status: offline

 
RE: Class VS. ID - 6/11/2003 11:44:48   
Quick tip...

Classes or IDs cannot begin with numbers.

_____________________________

SEO Consultants Directory
Find Search Engine Marketing Companies

(in reply to bobby)
bobby

 

Posts: 11394
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Class VS. ID - 6/11/2003 17:06:30   
good to know... no symbols either, correct?

<div class=" @#!!%" > :)
(homage to Qbert)

What about case? Caps vs. lower case?

I tend to use lc because I' m used to writing HTML that way (except when I type HTML, as you can see here :))

_____________________________

If con is the opposite of pro, is Congress the opposite of progress?


:)

(in reply to bobby)
austizzmo

 

Posts: 4
Joined: 6/19/2003
Status: offline

 
RE: Class VS. ID - 6/19/2003 21:24:13   
quote:

Classes or IDs cannot begin with numbers.


while it isnt good syntax... most major browsers will let you get away with using numerical characters as the first character of your id' s and class' s.

(in reply to bobby)
Gil

 

Posts: 7533
From: North Carolina, USA
Status: offline

 
RE: Class VS. ID - 6/19/2003 21:34:59   
quote:

most major browsers will let you get away with using numerical characters as the first character of your id' s and class' s


" MOST" ? So how do I know the one client who wants a consultant for his project and is ready to pay BIG $ is not one those that are not using MOST browsers? Sorry, most isn' t good enough :)

_____________________________

Gil Harvey, 1947-2004

(in reply to austizzmo)
Page:   [1]

All Forums >> Web Development >> Cascading Style Sheets >> Class VS. ID
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts