可能重复:
多个具有相同ID的元素响应一个 CSS ID 选择器
下面是我正在测试的示例代码,我很困惑.每个人都说我们可以使用或者我们应该每个 id 只使用一次,但我有测试使用它多次但它给了我正确的输出.
Below is the example code that I was testing and I got confused. Every one says that we can use or we should use only one time per id, but I have testes using using it multiple times but its giving me the correct output.
我该怎么办?
在这个例子中,它有点像我的类
It's kinda working same like class for me in this example
代码:
<html>
<head>
<style>
#exampleID1 { background-color: blue; }
#exampleID2 { text-transform: uppercase; }
</style>
</head>
<body>
<p id="exampleID1">This paragraph has an ID name of "exampleID1" and has a blue CSS defined background.</p>
<p id="exampleID2">This paragraph has an ID name of "exampleID2" and has had its text transformed to uppercase letters.</p>
<address id="exampleID1">
Written by W3Schools.com<br />
<a href="mailto:us@example.org">Email us</a><br />
Address: Box 564, Disneyland<br />
Phone: +12 34 56 78
</address>
<blockquote id="exampleID1">
Here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation.
</blockquote>
</body>
</html>
请查看上面的代码并回答我为什么我们不应该在一个页面中使用两次 id 选择器而它工作正常.
Please see the above code and answer me that why we should not use id selector two times in a page while its working fine.
一个 id 在一个页面中必须是唯一的.如果要描述一组元素,请使用类.
An id must be unique in a page. Use a class if you want to describe a group of elements.
为什么我们不应该在一个页面中使用 id 选择器两次而它工作正常.
why we should not use id selector two times in a page while its working fine.
您犯了一个错误,这取决于每个浏览该页面的浏览器来弥补它.你不能确定他们都会.
You are making an error and depending on every browser that will ever view the page to compensate for it. You can't be sure they all will.
这篇关于对多个 HTML 标签使用相同的 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!