W3C validation error “duplicate ID” although the I

2019-08-30 22:49发布

问题:

In my website I use CSS3 media queries for different styles on mobile. Then in my HTML code I add some div to show only in mobile device that duplicate another div that I hide.

In W3C validation it is an error, with "Duplicate ID".

But the ID not is duplicate because one of this is hidden.

How can I resolve this problem?

回答1:

The id attribute‘s value

[…] must be unique amongst all the IDs in the element's home subtree […]

So it doesn’t matter if the element is visually hidden.

Make them unique, or use some other hook, e.g. a class value.