Home > database >  How can I conditionally apply styling to one React property in a paragraph?
How can I conditionally apply styling to one React property in a paragraph?

Time:06-09

I have such a condition:

<p style={{color:props.age >= 10 ? 'green' : 'orange'}}>Age: {props.age}</p>

I do not want it to color the "Age" only the number.

enter image description here

CodePudding user response:

<p>Age: <span style={{color:props.age >= 10 ? 'green' : 'orange'}}>{props.age}</span></p>
  • Related