代码之家  ›  专栏  ›  技术社区  ›  flash

将闪烁光标的位置居中而不更改占位符的位置

  •  0
  • flash  · 技术社区  · 6 年前

    我在做一个 website 我想把闪烁光标的位置居中,占位符也居中。

    此刻在占位符上 what are you looking for... ,闪烁的光标从左侧开始,如下所示。

    enter image description here



    我用于占位符和闪烁光标的CSS代码是:

    闪烁光标 :

    .input-searchicon input{
    padding-left: 40px;
    }
    

    占位符:

    ::-webkit-input-placeholder {
     text-align: center;
    
    
    }
    
    :-moz-placeholder { /* Firefox 18- */
     text-align: center;  
    
    
    }
    
    ::-moz-placeholder {  /* Firefox 19+ */
     text-align: center;
    
    
    }
    
    :-ms-input-placeholder {  
     text-align: center; 
    
    
    }
    


    问题陈述:

    我想知道我应该在上面的CSS代码中做些什么更改,以便 闪烁的光标从中心开始,占位符也居中。

    2 回复  |  直到 6 年前
        1
  •  2
  •   Saman    6 年前

    输入的文本也应该居中。将输入样式更改为:

    .input-searchicon input{
       padding-left: 40px;
       text-align: center;
     }
    
        2
  •  1
  •   Unmitigated    6 年前

    只是使用 text-align: center input .

    .input-searchicon{
      text-align: center;
    }
    
    
    ::-webkit-input-placeholder {
     text-align: center;
    
    
    }
    
    :-moz-placeholder { /* Firefox 18- */
     text-align: center;  
    
    
    }
    
    ::-moz-placeholder {  /* Firefox 19+ */
     text-align: center;
    
    
    }
    
    :-ms-input-placeholder {  
     text-align: center; 
    
    
    }
    <input type="text" placeholder="what are you looking for" class="input-searchicon"/>