gpt4 book ai didi

javascript - 如何将 HTML 输入光标定位在居中占位符的开头

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:59 24 4
gpt4 key购买 nike

如何将光标定位到占位符的开头(而不是输入字段的开头)而不是中间,同时仍保持占位符文本居中?

<input type="text" name="input_query" id="input_query" autofocus style="text-align: center; width: 100%" placeholder="Describe what's happening in your photo" autocomplete="off"/>

最佳答案

使用 ::placeholder 仅将 CSS 应用于占位符:

input {
width: 100%
}
input::placeholder {
text-align: center;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autocomplete="off"/>

如果您希望光标出现在占位符的开头,您可以做类似的事情,尽管它很奇怪并且一旦用户开始输入就不会居中:

input {
width: 65%;
padding-left: 35%;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autocomplete="off"/>

关于javascript - 如何将 HTML 输入光标定位在居中占位符的开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50093680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com