我想知道是否可以根据主体 ID 的值定义元素的样式。
这很难解释,但像这样的东西是理想的:
HTML:
<body id="home">
CSS:
body#home {
a { /* code here */ }
p { /* code here */ }
}
body#profile {
a { /* different code here */ }
p { /* different code here */ }
}
我知道我可以做到:
body#home a { /* code here */ }
但这变得非常重复。
期待您的回复
彼得
最佳答案
如果你使用类似 SASS 的 CSS 框架,你可以做到这一点或 LESS
这是 documentation关于如何使用 LESS 做到这一点。希望这会有所帮助。
关于css - 如何根据其父元素制作 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20382654/