react项目中CSS继承(CSS样式复用)
.green-flag { width: 2rem; height: 2rem; padding: 0.375rem; border-radius: 0.25rem; user-select: none; user-drag: none; cursor: pointer; } .green-flag:hover { //冒号:的含义是此样式的不同状态下 background-color: $motion-light-transparent; } .green-flag.is-active { //我的理解为CSS样式的继承,样式抽取 background-color: $motion-transparent; }
const GreenFlagComponent = function (props) { const { active, className, onClick, title, ...componentProps } = props; return ( <img className={classNames( className, styles.greenFlag, { [styles.isActive]: active //如果active=true,就采用子样式。否则使用父类样式 } )} draggable={false} src={greenFlagIcon} title={title} onClick={onClick} {...componentProps} /> ); };
相关推荐
游走的豚鼠君 2020-11-10
81417707 2020-10-30
ctg 2020-10-14
小飞侠V 2020-09-25
PncLogon 2020-09-24
jipengx 2020-09-10
颤抖吧腿子 2020-09-04
wwzaqw 2020-09-04
maple00 2020-09-02
青蓝 2020-08-26
罗忠浩 2020-08-16
liduote 2020-08-13
不知道该写啥QAQ 2020-08-02
pengruiyu 2020-08-01
wmd看海 2020-07-27
孝平 2020-07-18
Eduenth 2020-07-05
iftrueIloveit 2020-07-04