संभव डुप्लिकेट:
Several elements with the same ID responding to one CSS ID selectorएकाधिक HTML टैग्स में एक ही आईडी का उपयोग करना?
नीचे उदाहरण कोड है कि मैं परीक्षण किया गया था और मैं उलझन में मिल गया। हर कोई कहता है कि हम इसका उपयोग कर सकते हैं या हमें प्रति आईडी केवल एक बार उपयोग करना चाहिए, लेकिन मेरे पास कई बार इसका उपयोग करके परीक्षण है लेकिन यह मुझे सही आउटपुट दे रहा है।
मुझे क्या करना चाहिए?
यह थोड़े इस उदाहरण में मेरे लिए एक ही तरह वर्ग काम कर रहा है
कोड:
<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:[email protected]">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>
कृपया उपरोक्त कोड देख सकते हैं और मुझे जवाब यही कारण है कि हम एक पृष्ठ समय में आईडी चयनकर्ता दो बार प्रयोग नहीं करना चाहिए यह ठीक काम कर रहा है।
सीएसएस वास्तव में परवाह नहीं करता है यदि आप आईडी और कक्षाओं का उपयोग करते हैं। जावास्क्रिप्ट परवाह करता है। जावास्क्रिप्ट बहुत परवाह करता है। – SpaceBeers
सिर्फ इसलिए कि आप इसका मतलब यह नहीं कर सकते कि आपको चाहिए। – BoltClock