你可以使用同一个id一次为多个html页面吗? [英] Can you use the same id once for multiple html page?

查看:378
本文介绍了你可以使用同一个id一次为多个html页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解html页面中一个id的概念。作为一个noob,我只是想知道你是否可以为不同的html页面使用同一个id。这会被认为是马虎么? $ b

例如,< div id =1>< / div> )在index.html中,并在product.html中再次使用< div id =1>< / div> 。这是否认为不好?



我试图做一个搜索,但没有找到答案。
谢谢!



!编辑!谢谢你的答案。赞赏!

解决方案

一个id只能在单个文档上使用一次。它用于仅在页面上出现一次的元素(想想顶部导航栏)。类用于可以出现多次的元素(例如,考虑特别样式的表,可重复的信息块或者共享特定特征的事物,例如在此浏览器宽度上,此块跨越6列引导)。在不同的页面上使用相同的ID是完全正常的。通常你会为你的布局制作一个框架/模板,每个元素在使用这个模板的每个页面上的样式都是相同的。然后在不同的页面上为同一元素使用相同的id是很有帮助的。 (或者:在每个页面上改变页面的布局会被认为是渺茫的,对每个元素使用不同的id,因为维护你的页面是很困难或不可能的。)


I understand the concept of one id in an html page. As a noob, i was just wondering if you can use the same id once for different html pages. Will that be consider sloppy?

For instance, <div id="1"></div> (used only once)in index.html and used <div id="1"></div> again in product.html. Is that consider bad?

I tried to do a search but found no answers. Thank you!

!edit! Thank you for the answer guys. Appreciated!

解决方案

An id should only be used once on a single document. It is used for elements that only should appear once on the page anyway (think of a "top navigation bar"). Classes are used for elements that can appear more than once (think of a "particularly styled table", a "repeatable block of information" or things that share particular charasteristics such as "on this browser width this block spans 6 columns" in for example bootstrap). It is perfectly normal to use the same id on different pages. Usually you'll make a skeleton/template for your layout, where each element will be styled the same on each page that uses this template. It is then helpful to have the same id for the same element across different pages. (or: It would be considered sloppy to change the layout of the page on every page, using different id's for each element, as it would be hard or impossible to maintain your pages.)

这篇关于你可以使用同一个id一次为多个html页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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