Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Append text with styling

I was wondering how to merge 2 pieces of text together in React JS. Difference is 1 section of the text has its own unique styling. Example code below:

<div>
    <div>
      {'If you haven\'t recieved an email, please check your spam filter or '}
    </div>
    <div style={{ color: 'red' }}>
      try another email address
    </div>
</div>

I have tried using flex and flex direction as row in the parent div, but have had no luck. This is what happens with flex in the parent div.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could use span (instead of div).

The span tag is an inline container used to mark up a part of a text and it doesn’t break to the next line

<div>
  <span>
    {'If you haven\'t recieved an email, please check your spam filter or '}
  </span>
  <span style={{ color: 'red' }}>
    try another email address
  </span>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading