CSS3 - How to style the selected text in textareas and inputs in Chrome?

后端 未结 3 1315
轻奢々
轻奢々 2020-12-01 16:21

EDIT: As @geca noted in the comments, this is a known WebKit bug. Let\'s hope it gets fixed soon!

The ::selection pseudo-element allows one to style th

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 16:52

    Is a

    with contenteditable an option? Functions just list a

    <p> Highlights just fine in Chrome!

    <div contenteditable> Highlights just fine in Chrome!

    CSS:

    textarea, input, p, div {
        width: 400px;
    }
    
    #div-textarea {
        -webkit-appearance: textarea;
        height: 32px;
        overflow: auto;
        resize: both;
    }
    
    ::selection {
        background-color: black;
        color: white;
    }
    

    Output (Chrome):

    enter image description here

提交回复
热议问题