5 replies [Last post]
Raven21633
Raven21633's picture
Offline
newbie
Last seen: 12 years 49 weeks ago
Joined: 2007-12-15
Posts: 6
Points: 0

First let me say Hello!

I'm new here and this is my first post.

Of course I'm here because I'm an old dog trying to learn new tricks, and instead I feel like I'm trying to learn Chinese ha ha. I'm trying to put my content into one of those free web templates and it's not working out for me, so I'm about to pull my hair out.

As I was searching to see if anyone else had posted about my particular problem, I ran across a tutorial here about Classes and ID's. Unfortunately, this tutorial is the exact same as the million other tutorials on the internet. They all say "You must use an ID only ONCE per page", and then just leave you to accept this on faith alone. Why once per page?

Of course this stupid template is made with nothing BUT ID's, so to get the look I want I've just been using them over and over again on the same page. Works fine for me. At least I've seen no ill effect.

So in laymans terms, why is an ID to be used only once? Why can't it be used in multiple places?

On another note, is CSS and XHTML really worth all the bother? It seems they took a perfectly good working code (HTML 4) and turned it into something requiring an MIT graduate in the top 10% of his class. I'm reaching a point of frustration where I'm ready to chuck this hoity-toity XHTML and go back to my old layout.

Thanks
Raven

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 6 days 21 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

unique id

Hi Raven,
Id's are used when you want to target a specific element, not only with CSS but also DOM.
When you think of manipulating elements via DOM or JavaScript it may be easier to see why id's should be unique. Let's say you want to target a specific element and change the content within that element via DOM scripting. It is much easier to get a hold of the element if it has an ID and if it is the only element on the page with that id.
So hopefully that makes it easier to understand why having a unique id is useful. It is also invalid to have multiple id's and may cause some browsers to do unexpected things, like load in quirks mode or throw JavaScript errors.

As for learning XHTML, that's a choice you will have to make. You could stick with HTML just try to keep it valid. There are topics all over the forms and web on why you should validate your markup.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

The question of HTML Vs.

The question of HTML Vs. XHTML gets covered quite regularly here in some depth please hunt around and have a read of those threads, but as for XHTML being complex it is not at all it only requires a few strict rules regarding code syntax.

As for disregarding instructions regarding the use of an ID only once that is simply foolish Smile yes ask the question 'why' but accept that as it is the repeated instruction everywhere that it must be adhered to; as for your pages seemingly working using repeated ID names they wont be! I would check in a modern browser and also validate your work
.

Use classes if you wish to repeat rulesets for multiple elements, classes belong to CSS ID's on the other hand belong to markup in general and have other uses apart from attaching styling to an element and have to be unique to prevent conflicts where a script needs to know which element it is dealing with.

Edit/ beaten to it!

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Raven21633
Raven21633's picture
Offline
newbie
Last seen: 12 years 49 weeks ago
Joined: 2007-12-15
Posts: 6
Points: 0

Thanks fellows, And please

Thanks fellows,

And please accept my apologies for being a bit terse tonight. I've been dealing with this for hours now and now that I'm getting on in years (and expecting my first grand-child) I find that my patience level (and subsequent frustration tolerance) has decreased quite significantly :blushing:

Thanks again.
Raven

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

No apologies required,

No apologies required, hadn't noticed any particular terseness, but do understand decreasing tolerance with advancing years Smile

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

syrupcore
Offline
Enthusiast
Last seen: 11 years 42 weeks ago
Timezone: GMT-8
Joined: 2004-03-10
Posts: 108
Points: 0

Think of it like Drivers Licenses

You and only you can have your ID. Anyone else caught with your ID is in trouble.
You and everyone you know can have a 'Class C' license.

If you and 100 other people had the same ID, how chaotic would voting be? or banking? or college registration? or or or... same exact idea.