CSS class and id with the same name

前端 未结 4 1158
暗喜
暗喜 2020-12-07 22:29

Is there anything wrong with having a css class and id with the same name? Like .footer for the article/post\'s footer and #footer for the page footer.

4条回答
  •  悲哀的现实
    2020-12-07 22:55

    Nope, perfectly acceptable.

    A class is defined using a . and an ID is defined using a #. So as far as the browser is concerned, they're two totally separate items.

    The only thing to be careful of is generating any confusion for yourself. It's probably best practise to keep the names different purely for code readability, but there's no harm in them being the same.

提交回复
热议问题