How do I have different font colors in a textarea?

后端 未结 3 1438
醉酒成梦
醉酒成梦 2021-02-09 10:29

I want the font color to change in a textarea as I type in specific keywords, like in Visual Studio.

I have not seen this anywhere, so I don\'t know if this is possible

3条回答
  •  耶瑟儿~
    2021-02-09 11:17

    It's not possible.

    Way to go is to make textarea's font, but not cursor, transparent using color:#000;-webkit-text-fill-color:transparent, then create underlying, 100% overlapping div to which content of textarea will be copied + formatted on textarea's oninput event.

    You'll need to adress (or avoid) some issues coming out of syncing these two elements, like scrolling for example, but it can be done. I made my own HTML editor this way.

    AFAIK, css property -webkit-text-fil-color is supported in Opera, Chrome and should be in soon-to-be-released Firefox v.48.

提交回复
热议问题