以下代码当我使用id
属性作为父母margin-bottom
未得到应用,而当我将其用作父母class
时,它起作用,是否覆盖或优先事项?当父母身份为ID时,CSS规则不起作用
.prof {
margin: 10px 0 0;
.parent & {
margin: 15px 0 0;
position: relative;
}
.js-prof,
.js-prof-layout {
.prof {
margin-bottom: 10px;
}
}
margin-bottom: 10px
不与父母工作作为id
:
.prof {
margin: 10px 0 0;
#parent & {
margin: 15px 0 0;
position: relative;
}
.js-prof,
.js-prof-layout {
.prof {
margin-bottom: 10px;
}
}
请注意,这是完全一样的页面
margin-bottom: 10px
当父被用作class
工作但唯一的区别是添加父母作为id
不工作,同时将其添加为class
作品!任何解释?谢谢
你将需要演示这个。 –
您的CSS规则正按预期工作 - 它们不会被破坏。你应该阅读[CSS特定性](https://css-tricks.com/specifics-on-css-specificity/) – chazsolo
我们需要看到你的HTML也使用这些类,否则我们不能帮你。 – TylerH