我希望使用jss样式。
.a{
height: 20px;
}
.b{
height: 40px;
}
.a,.b{
width: 100px;
}
制定规则c
并将该课程添加到a
和b
c: {
width: '100px'
}
制作一个对象common
并将其合并到a
和b
规则
const common = {
width: '100px',
};
a: {
height: '20px',
...common
}
b: {
height: '40px',
...common
}
有没有更好的方法?
答案 0 :(得分:2)
我觉得更容易解析的一个更简单的替代方法是,通过用引号引起来将键设置为字符串:
'.a, .b': {
width: 100px;
}
答案 1 :(得分:1)
扩展插件(默认启用)如何?
https://cssinjs.org/jss-plugin-extend
const styles = {
buttonColor: {
background: 'red'
},
button: {
extend: 'buttonColor',
fontSize: '20px'
}
}