React学习笔记:设置行内样式style属性

前端之家收集整理的这篇文章主要介绍了React学习笔记:设置行内样式style属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在react中,可以这样来设置行内样式:

  1. render() {
  2. const styles = {color:"red",fontSize:"16px"};
  3. return (
  4. <div style={styles}></div>
  5. );
  6. }

注意 styles 是一个json对象,key对应css属性名并且转为驼峰式命名。

更加便捷的写法:

  1. render() {
  2. return (
  3. <div style={{color:"red",fontSize:"16px"}}></div>
  4. );
  5. }

参考:https://react-cn.github.io/react/tips/inline-styles.html

猜你在找的React相关文章