最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to reuse the same style rule with multiple selectors - Stack Overflow

programmeradmin6浏览0评论

I want this using jss styling.

.a{
height: 20px;
}
.b{
height: 40px;
}
.a,.b{
width: 100px;
}

Try 1

Make a rule c and add the class to both a and b

c: {
width: '100px'
}

Try 2

Make a object mon and merge them to both a and b rule

const mon = {
   width: '100px',
};

a: {
height: '20px',
..mon
}
b: {
height: '40px',
..mon
}

Is there any better way possible ?

I want this using jss styling.

.a{
height: 20px;
}
.b{
height: 40px;
}
.a,.b{
width: 100px;
}

Try 1

Make a rule c and add the class to both a and b

c: {
width: '100px'
}

Try 2

Make a object mon and merge them to both a and b rule

const mon = {
   width: '100px',
};

a: {
height: '20px',
...mon
}
b: {
height: '40px',
...mon
}

Is there any better way possible ?

Share Improve this question edited Feb 14, 2019 at 19:38 isherwood 61.1k16 gold badges120 silver badges168 bronze badges asked Aug 7, 2017 at 22:20 Slim ShadySlim Shady 1,0852 gold badges13 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

How about extend plugin (enabled by default)?

https://cssinjs/jss-plugin-extend

const styles = {
  buttonColor: {
    background: 'red'
  },
  button: {
    extend: 'buttonColor',
    fontSize: '20px'
  }
}

A simpler alternative that I feel is easier to parse would be to set the key to be a String by wrapping in quotes:

'.a, .b': {
   width: 100px; 
}
发布评论

评论列表(0)

  1. 暂无评论