Search code examples
cssreactjsstyles

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


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


Solution

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