在react中,可以这样来设置行内样式:
- render() {
- const styles = {color:"red",fontSize:"16px"};
- return (
- <div style={styles}></div>
- );
- }
注意 styles
是一个json对象,key对应css属性名并且转为驼峰式命名。
更加便捷的写法:
- render() {
- return (
- <div style={{color:"red",fontSize:"16px"}}></div>
- );
- }