Select first letter of input value and change it's color via CSS

前端 未结 5 1723
忘了有多久
忘了有多久 2021-01-05 20:48

Is there a way to select the text input values first letter and change its color via CSS in the stylesheet? so for example, I have



        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 21:25

    I don’t think that input boxes will allow changing the style of the first letter – it seems the OS does not make it possible. So you can make a div with contentEditable property equal to "true", and get its content with JavaScript, or a small workaround with two inputs aligned horizontally, or something. See this:

    
        
            .leftInput{
                border-bottom: 1px solid black;
                border-left: 1px solid black;
                border-top: 1px solid black;
                border-right: 0px;
                width:10px;
                color:red;
            }
            .rightInput{
                border-bottom: 1px solid black;
                border-right: 1px solid black;
                border-top: 1px solid black;
                border-left: 0px;
                margin-left: 0px;
            }
        
        
            
        
    
    

    .leftInput {
        border-bottom: 1px solid black;
        border-left: 1px solid black;
        border-top: 1px solid black;
        border-right: 0px;
        width: 10px;
        color: red;
    }
    .rightInput {
        border-bottom: 1px solid black;
        border-right: 1px solid black;
        border-top: 1px solid black;
        border-left: 0px;
        margin-left: 0px;
    }

提交回复
热议问题