【发布时间】:2018-04-26 19:48:40
【问题描述】:
在 CSS/LESS 中我会这样做:
.button {
&:active, .active {
background-color: #393939;
border-color: #2F2F2F;
box-shadow: inset 0 0 0 1px #3D3D3D,
inset 0 2px 0 #323232;
}
}
:active 是我的按钮在被点击时的样式,.active 是我在按钮处于活动状态时添加 的类(用于可切换按钮)。
styled-components 我现在有这个:
import styled from 'styled-components';
export default styled.button`
width: 32px;
height: 32px;
border-radius: 5px;
background-color: #535353;
border: 1px solid transparent;
cursor: pointer;
outline: none;
padding: 4px;
&:active, /* what to do here?? */ {
background-color: #393939;
border-color: #2F2F2F;
box-shadow: inset 0 0 0 1px #3D3D3D,
inset 0 2px 0 #323232;
}
`
但我不知道如何根据某些属性重用所有这些 :active 样式。我知道我可以使用 ${props => prop.active} 访问道具,但我不知道如何在不重复所有这些样式的情况下重复使用该样式块。
我该怎么做?
【问题讨论】:
标签: css reactjs styled-components