Javascript only affects one element

后端 未结 2 1766
执念已碎
执念已碎 2021-01-23 12:18

I don\'t understand, the border is only visible on the first item, why?

HTML

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 12:53

    "document.getElementById" means "Returns a reference to the element by its ID", see here; and id means identity, you should have only one element in your dom tree per id.

    If you want to style multiple elements, try to use class.

    HTML

    Content 1
    Content 2

    CSS

    .item { border-top: 1px solid #0ea2c7; }
    

提交回复
热议问题