7

我想知道是否可以将占位符和用户将在文本字段中输入的输入居中。我想这是可能的,但我无法弄清楚。有人可以帮忙吗?我有问题的文本字段的代码如下...

<input type="text" style="font-weight:bold:" name="kword" id="kword" autofocus ="on" placeholder="Enter Keyword(s)" autocomplete ="on"/>

谢谢

4

3 回答 3

4

这可以用来text-align:center

CSS:

input, input[placeholder] {
    text-align: center;
}
于 2012-09-13T10:39:17.270 回答
2

定位浏览器特定的占位符伪元素,如下所示:

input {
  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" style="font-weight:bold;" placeholder="Enter Keyword(s)" />

于 2016-06-16T11:37:24.070 回答
0

就我而言,一个好的解决方案是:

div.search {display: flex;}

input::placeholder {align-self: center;}
于 2020-12-24T08:49:17.517 回答