【发布时间】:2018-02-22 00:23:33
【问题描述】:
我有以下 ui 组件:
const StyledLabel = styled.div`
color: ${(props) => props.theme.colors.black};
`;
const Label = ({
text,
marginBottom,
}) => (
<StyledLabel
style={{ marginBottom }}
>
{text}
</StyledLabel>
);
我想要做的是删除样式属性并让样式组件处理边距底部......所以我现在有:
const StyledLabel = styled.div`
color: ${(props) => props.theme.colors.black};
margin-bottom: ${(props) => props.marginBottom};
`;
const Label = ({
text,
marginBottom,
}) => (
<StyledLabel
marginBottom={marginBottom}
>
{text}
</StyledLabel>
);
上面的问题是应用于元素的 CSS 是:
margin-bottom: 8;
不是想要的8px -- 我可以让样式组件像style 那样神奇地添加px 吗?或者我是否需要更新我的应用程序,从通过 marginBottom 8 到 8px ?
【问题讨论】:
-
你能把
StyledLabel改成追加px,比如const StyledLabel = styled.div` color: ${(props) => props.theme.colors.black};margin-bottom: ${(props) => props.marginBottom + 'px'}; `;