0

How to make diffrent words, a diffrent color

Example: Soap- yellow (this is yellow only) Guitar-brown(this brown only)

31st May 2020, 10:28 PM
Shawnn
Shawnn - avatar
4 Respostas
+ 3
A simple js solution <p><span>soap</span> <span>guitar</span></p> <script> var a=document.querySelectorAll("span"); colors=["yellow","brown"]; for(i in a){ if(i<a.length){ a[i].style.color=colors[i]; }} In case of css just give each span a different id and select it with that id and provide it color attribute
31st May 2020, 11:16 PM
Abhay
Abhay - avatar
0
You could parse your document with JS and replace each occurrence with a spanned version with the designated formatting. This would be a pure JS-only way. If you're using a framework, the possible solutions may vary.
31st May 2020, 10:45 PM
Sandra Meyer
Sandra Meyer - avatar
0
With precondition that each color is already given within a span? And a little more effort to apply on full text search 🙃
31st May 2020, 11:17 PM
Sandra Meyer
Sandra Meyer - avatar
0
Make diferent class for different color and use any inlini element to implement that class to that word like :- In css : .yellow { color: yellow; } .brown { color:brown } In html :- Hi, <span class = "yellow"> Abhay </span > is <span class = "brown">cool</span>
31st May 2020, 11:52 PM
Abhay
Abhay - avatar