behavior of browsers for css application when multiple elements share same id

后端 未结 3 2118
有刺的猬
有刺的猬 2020-12-21 20:02

I understand that IDs are supposed to be unique in HTML documents. But a lot of HTML pages are sloppy and don\'t follow the rule. My question is: how do browsers handle CSS

3条回答
  •  死守一世寂寞
    2020-12-21 20:12

    For an example of unintended consequences, see this question I answered:

    Yet another IE 'Object expected' error with no information

    You have this HTML, once for each tab:

    Introduction

    The problem is that you're specifying two elements with id='introduction'.

    For various reasons, you should not do that:

    • It's causing validation errors.

      Line 37, Column 27: Duplicate ID introduction.
      Line 36, Column 39: The first occurrence of ID introduction was here.

    • It's breaking your tabs in IE7.

提交回复
热议问题