我想使用 jss 样式。
.a{
height: 20px;
}
.b{
height: 40px;
}
.a,.b{
width: 100px;
}
尝试1
创建一个规则c
并将该类添加到a
和b
c: {
width: '100px'
}
尝试2
创建一个对象 common
并将它们合并到 a
和 b
规则
const common = {
width: '100px',
};
a: {
height: '20px',
...common
}
b: {
height: '40px',
...common
}
有没有更好的办法?
最佳答案
如何扩展插件(默认启用)?
https://cssinjs.org/jss-plugin-extend
const styles = {
buttonColor: {
background: 'red'
},
button: {
extend: 'buttonColor',
fontSize: '20px'
}
}
关于javascript - 如何对多个选择器重用相同的样式规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45556538/