css div id每页仅使用一次 [英] css div id used only once per page

查看:112
本文介绍了css div id每页仅使用一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用CSS时,最佳做法是每页只使用一次div ID。我知道每个id必须是唯一的,但可以使用多次。与我的开发团队进行讨论,发现一个人的印象是,每页只能使用div id标签一次。

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.

每个ID为1的示例第:

Example of 1 id per page:

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

每页多个ID的示例:

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

我希望很清楚。

推荐答案

你可以使用id =属性作为很多时候你需要,但属性的内容应该是唯一的。没有唯一值是一个HTML错误。

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.

更多信息位于W3C - 元素标识符:id和类属性(HTML 4.01规范)。

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

这篇关于css div id每页仅使用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆