如何在没有 JS 的 Edge 中将光标置于具有占位符的文本输入中?

How to center the cursor in a text input having a placeholder in Edge without JS?

它适用于除 Edge 之外的所有浏览器。是否有纯粹的 CSS 解决方法?

input {
  text-align: center
}
<input placeholder="placeholder" />

Tamás,不错的发现!这似乎是我们表单控件的错误。请注意,游标在没有占位符时遵守指令,但在有占位符时退回到左对齐。这似乎是无意的,值得深入研究。

试试这个。当您已经 css 的输入字段文本居中

时,这是对边缘的修复
 if(window.navigator.userAgent.search(/edge/ig)){

     $("#inputfield").focus((e)=>{
        $("#codefield").attr({placeholder: ""});
     });

     $("#codefield").blur((e)=>{
        $("#codefield").attr({placeholder: "Your Placeholder"});
     });

 }

您可以通过以下方式使 caret placeholder 居中在输入字段中

html

<input type="text" placeholder="type something..."/>

风格 css

input{
    text-align: center;
 }

祝你好运