Css 使用const和“React inline style”;“文本”;
我希望我的元素有一个常量样式和内联硬编码样式,假设我有:Css 使用const和“React inline style”;“文本”;,css,reactjs,Css,Reactjs,我希望我的元素有一个常量样式和内联硬编码样式,假设我有: const style = { cursor: "pointer", border: "2px solid #b1b1b1", borderRadius: "8px", padding: "0px 10px 0px 10px", backgroundColor: "green" } 但是我也希望元素有额外的样式,比如说宽度 <div style={style{width: "20%"}}&g
const style = {
cursor: "pointer",
border: "2px solid #b1b1b1",
borderRadius: "8px",
padding: "0px 10px 0px 10px",
backgroundColor: "green"
}
但是我也希望元素有额外的样式,比如说宽度
<div style={style{width: "20%"}}>test</div>
测试
这不起作用,我如何才能做到这一点?您可以使用语法指定样式
<div style={{...style, ...{width: "20%"}}}>test</div>