是否可以:root
在 ReactJS 中更改 CSS变量?寻找--base
根据用户从.change-me
输入颜色中选择的内容来更改颜色代码的解决方案
演示:https : //codepen.io/anon/pen/RgXBEK
CSS
:root {
--base: $primary;
}
react
changeTheme(e){
console.log(e.target.value);
}
class App extends React.Component {
render() {
return (
<div className="row">
<div className="col-xs-12 text-center">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam voluptates ut eaque, voluptatum veniam nostrum sequi numquam sint, excepturi amet unde quis, ipsum ducimus reprehenderit eligendi pariatur animi esse sed.</p>
<input
className=""
type="color"
onChange={this.changeTheme.bind(this)}
/>
<br/><br/>
</div>
</div>
);
}
}
ReactDOM.render(<App />, window.document.getElementById('myDiv'));