Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

css div id used only once per page

In using CSS is it best practice to use a div id only once per page. I know each id has to be unique but could be used multiple times. A discussion with my development team and it came up that one person was under the impression that you could only use the div id tag once per page.

Example of 1 id per page:

<page>
  <div id="test">Some Text</div>
  <div class="test12">More Text</div>
</page>

Example of multiple id's per page:

<page>
  <div id="test">Some Text</div>
  <div id="test12">More Text</div>
</page>

I hope that's clear enough. If not let me know and I can try to explain it better.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can certainly use the id="" attribute as many times as you need, but the contents of the attribute should be unique. Not having a unique value is a HTML error.

If you need multiple items to have the same attribute, then you can set them as a class.

More info is at the W3C - Element identifiers: the id and class attributes (the HTML 4.01 Specification).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...