Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set background color to the text only in react native

in html I can achieve this by

<span style="background-color:red">ketan</span>

but in react native how to implement this so that color will be applied to the text only.

like image 614
ketan kulkarni Avatar asked Jul 16 '18 09:07

ketan kulkarni


1 Answers

If you want the background color to only encompass the text, you can use this:

<Text style={{backgroundColor: 'blue', alignSelf: 'flex-start'}}>
    Ketan
</Text>

And just change alignSelf as needed, you need to set this property if you dont want the text to take the whole width of the container

like image 101
Raphael Estrada Avatar answered Oct 19 '22 11:10

Raphael Estrada