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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using multiple id="foo" in one document&validation 3

Status
Not open for further replies.

TFfan

Programmer
Jan 18, 2002
192
CA
Line 29, column 10: ID "title" already defined (explain...).
<div id="title">Mother, Not Mother</div><hr class="books" /><br />
^
Line 24, column 10: ID "title" first defined here (explain...).
<div id="title">Now You Care</div><hr class="books" /><br />

That's the error message I get. Now it's just a quick cut&paste to fix in my css, but I thought you could reuse id styles in the same page. Am I missing something?
 
Right, but maybe this is inefficient, but I have multiple paragraphs and each paragraph have many of the same attributes so I create an id style and go from there. But the paragraphs also have attributes that make them unique so I give each of them a different class. So my structure looks something like this:

<div id="para" class="para1">
paragraph 1 text
</div>

<div id="para" class="para2">
paragraph 2 text
</div>

etc.

I should just use a class when I use an id and an id when a class? Thanks.
 
You have made the correct deduction :)

You can also use tags in the CSS

<style>
DIV {}
P {}
</style>

----------
I'm willing to trade custom scripts for... [see profile]
 
Yeah, I knew you could use tags in CSS, but thanks just the same, stormbind. I've been using CSS for a long time now, but only starting validating my sites recently. It's going to be tough to reverse my way of thinking. Thanks again.
 
I have multiple paragraphs and each paragraph have many of the same attributes so I create an id style and go from there. But the paragraphs also have attributes that make them unique so I give each of them a different class..."

You've just got it the wrong way round. The things that make an element unique should be given an id, as an id uniquely identifies a single element on your page. Properties that you want to assign to several elements should be attached to a class, as a class classifies several elements.

Having said that, and as you've probably noticed, most browsers will cope with the same id being mentioned twice - but it's sensible not to rely on them always doing so.

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top