以下代碼當我使用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