reactjs - how to set inline style of backgroundcolor?

前端 未结 3 1505
北荒
北荒 2020-12-29 01:19

I want to set the style properties of some elements but I don\'t have the syntax correct. Can anyone suggest where I am wrong?

import React from \'react\';
         


        
相关标签:
3条回答
  • 2020-12-29 01:39

    https://facebook.github.io/react/tips/inline-styles.html

    You don't need the quotes.

    <a style={{backgroundColor: bgColors.Yellow}}>yellow</a>
    
    0 讨论(0)
  • 2020-12-29 01:46

    If you want more than one style this is the correct full answer. This is div with class and style:

    <div className="class-example" style={{width: '300px', height: '150px'}}></div>
    
    0 讨论(0)
  • 2020-12-29 01:51

    Your quotes are in the wrong spot. Here's a simple example:

    <div style={{backgroundColor: "#FF0000"}}>red</div>
    
    0 讨论(0)
提交回复
热议问题