textarea::selection and ::-moz-selection

后端 未结 2 1508
北海茫月
北海茫月 2020-12-16 20:52

Is there a way to apply the ::selection and ::-moz-selection CSS pseudo-elements to the text inside a textarea?

textarea::selection         


        
相关标签:
2条回答
  • 2020-12-16 21:30

    According to this, it should work.

    Can you try giving it an !important?

    Can you try applying it to a different element than a textarea, e.g. a div? If it works there, it works differently for input elements - but I can't find any resources mentioning that.

    0 讨论(0)
  • 2020-12-16 21:37

    Updated as you said here, I'll update this question too:

    I disagree. It is working ;)
    Tested on Firefox 4.0b6

    I can confirm the following code works at least under Firefox 4.0b6 (Taken from my own answer)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>Test</title>
    <style type="text/css">
    
    p::-moz-selection, input::-moz-selection, textarea::-moz-selection {
        color: red;
        background-color: grey;
    }
    </style>
    </head>
    
    <body>
    <p>This paragraph is selection-aware.</p>
    <form action="#">
    <input type="text" id="itext" value="So is this input[text]" />
    <textarea id="itextarea">And this textarea, as well</textarea>
    </form>
    </body>
    </html>
    

    It may not be wroking programmatically, if you are not careful with what you are doing. Maybe you are trying to select something with jQuery.select() and you are selecting the textarea object instead of its content.

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