【发布时间】:2017-08-04 10:03:34
【问题描述】:
是否可以根据“内部修饰符”从“外部”设置块样式? 这是一个例子:
HTML
<div class="Header">
<div class="Button Header__button">
Seperate Block with optional modifier Button--expanded
</div>
</div>
button.css
.Button--expanded {
height: 100%; /* Default height of expanded buttons */
}
header.css
/* Expanded buttons within header have a different height */
/* Approach 1*/
.Header__button.Button--expanded {
height: 32px;
}
/* Approach 2*/
.Header__button--expanded {
height: 32px;
}
Button--expanded 类是由一些只知道 Button 控制/块本身的模块化 JS 动态添加的。因此Approach 1 工作“开箱即用”,而Approach 2 需要一些额外的JS 以某种方式将expanded 状态冒泡到Header 控件以将显式修饰符类Header__button--expanded 设置为Header__button 元素...
我知道在做出此类决定时没有绝对的对与错,但如果有人能指出每种方法的优缺点,我将不胜感激。
【问题讨论】: