Multicolor Text Highlighting in a Textarea or Text Input

后端 未结 4 910
情书的邮戳
情书的邮戳 2020-11-27 05:38

I\'d like to set text in a textarea or text input using different colors (one or the other is fine, I don\'t need both). Think of something like simple syntax highlighting.

相关标签:
4条回答
  • 2020-11-27 05:58

    No, you can't do this in a textarea or text input. Any CSS text-related property will affect the whole text within the the textarea/input. You'll need an editable element or document to achieve syntax highlighting. Example (works in all recent browsers; the last major browser not to support contenteditable was Firefox 2.0):

    <code contenteditable="true">
      <span style="color: blue">var</span> foo = <span style="color: green">"bar"</span>;
    </code>

    0 讨论(0)
  • 2020-11-27 06:00

    This can actually be done by using styling inside of the tag, this is a reference from one of my websites where i have done this

    <input style="border-radius: 5px; background-color: #000000; color: #ff0000; border-color:
     blue;" class="form-control" name="firstname" placeholder="What you were looking for?"
     type="text"
     required autofocus />
    
    0 讨论(0)
  • 2020-11-27 06:09

    Are you finding this?

    Use jQuery.colorfy

    Code: https://github.com/cheunghy/jquery.colorfy

    Demo: http://cheunghy.github.io/jquery.colorfy/

    Screencast: https://www.youtube.com/watch?v=b1Lu_qKrLZ0

    0 讨论(0)
  • 2020-11-27 06:11

    you can simply make a SPAN tag for selecting some part of the text, for example:

    Some <span style="color:#FF3333">text</span> here
    

    Wich will make the word text look in red

    0 讨论(0)
提交回复
热议问题