Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用const和“React inline style”;“文本”;_Css_Reactjs - Fatal编程技术网

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>