【发布时间】:2011-03-03 16:54:44
【问题描述】:
我打算像这样“嵌套”CSS ids
#content #caption { color: teal }
...
#footer #caption { margin: 2em 1em }
因为这是 SASS(一个 CSS 生成器)可以嵌套的方式...但是在一个 HTML 文档中,我们不能有两个同名的 ids,不是这样,所以上面的嵌套不会工作或不能很好地工作。 (尤其是如果需要 document.getElementById() 或 $('#caption') 或 $('caption') 来选择元素)。
我们可以使用
#content #content_caption { color: teal }
...
#footer #footer_caption { margin: 2em 1em }
但是为什么还要多一层嵌套呢?为什么不只是
#content_caption { color: teal }
...
#footer_caption { margin: 2em 1em }
?
【问题讨论】:
标签: css stylesheet styles sass nested