【发布时间】:2023-04-02 08:44:01
【问题描述】:
this.state.checkBool 是 true / false
这样的HTML结构,切换class1和class2
<div class='common class1'>
<div class='common class2'>
css 看起来像
common {
display: block;
background: grey;
}
.class1 {
position: absolute;
left: 1px;
right: auto;
top: 2px;
background: blue;
}
.class2 {
position: absolute;
left: auto;
top: 2px;
right: 30px;
background: yellow;
}
样式化组件
const Wrapper = styled.div`
display: block;
background: grey;
// Should this part use props to check true or false?
${prosp => }
`
我被困在如何切换类
<Wrapper toggle={this.state.checkBool ? class1 :class2 }/>
【问题讨论】: