如何在react加css样式?下面本篇文章就来给大家介绍一下在react中添加css样式的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
react加css的3种方法:
1. 行内样式
直接给对应的DOM元素添加style属性,遵循react的规则,写在{ }当中。
style={{
width:'200px',
height:'80px',
backgroundColor:'yellow',
fontSize:'24px',
textAlign:'center'
}}
>This is Page1!
2. 声明样式render(){
let mystyle={
width:'200px',
height:'80px',
backgroundColor:'yellow',
fontSize:'24px',
textAlign:'center'
}
return(
This is Page1!
}
3. 引入样式require('./mystyle.css');
更多React相关技术文章,请访问 React答疑 栏目进行学习!!