我可以检查父元素在sass中有特定的类吗? [英] Can I check parent element has specific class in sass?
本文介绍了我可以检查父元素在sass中有特定的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果父元素具有特定的类,我想有条件地分配值。 Exp:
I want to assign value conditionally if parent element has a specific class. Exp:
HTML
<div class="parent">
<div class="child">Some Text</div>
</div>
CSS
.child {
font-size: 16px;
}
但如果父元素具有名为 big的类
but if parent element has a class named "big"
HTML
<div class="parent big">
<div class="child">Some Text</div>
</div>
我要按以下方式更改值
CSS
.child {
font-size: 20px;
}
例如:
.child {
font-size: parent.hasClass('big') ? 20px : 16px;
}
如何在SASS中做到这一点?
How can I do that in SASS?
推荐答案
只需创建两个规则:
.child {font-size: 16px;}
.big .child {font-size: 20px;}
在SASS中应该是
In SASS it would be
.child
font-size: 16px
.big &
font-size: 20px
这篇关于我可以检查父元素在sass中有特定的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文