简体   繁体   English

如何在反应中添加内联 styles?

[英]How to add inline styles in react?

I'm new to react.我是新来的反应。 I've tried {{style=color: "red"}} but this gives me an error.我试过{{style=color: "red"}}但这给了我一个错误。 Appreciate if you can help me.感谢您能帮助我。

It's easy to add inline styles in react.在反应中添加内联 styles 很容易。 style={{color: "red"}} this is how you do it. style={{color: "red"}}这就是你的做法。

Here is an example from React Docs :这是来自React Docs的示例:

// Result style: '10px'
<div style={{ height: 10 }}>
  Hello World!
</div>

// Result style: '10%'
<div style={{ height: '10%' }}>
  Hello World!
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM