CSS inner id selectors

前端 未结 2 814
刺人心
刺人心 2021-01-23 06:11

I\'ve got below id selectors in a CSS file. Headerphoto and logo-box are inner id-selectors of header id. Do I really need to add those two as inner id-selectors? I can add them

2条回答
  •  旧巷少年郎
    2021-01-23 07:05

    It doesn't matter as long as only one of #headerphoto and #logo-box exist on each page and you're sure the structure for these three elements will be the same.

    It only really matters to add the #header ID if, on some pages, #headerphoto and #logo-box appear in elements that don't have id="header", your stylesheet is used by all these pages, and you want the styles to apply if and only if these elements are in that one. But in such a case, that'd make your page structure rather inconsistent, wouldn't it?

    Regarding performance, whether it's faster, slower or the same to nest ID selectors, I don't care, and neither should you, the stylesheet author, since ID selectors are already the fastest anyway.

提交回复
热议问题