admin管理员组文章数量:1405164
How can I position the cursor to be at the beginning of the placeholder (not the beginning of the input field) instead of the middle, while still keeping my placeholder text centered?
<input type="text" name="input_query" id="input_query" autofocus style="text-align: center; width: 100%" placeholder="Describe what's happening in your photo" autoplete="off"/>
How can I position the cursor to be at the beginning of the placeholder (not the beginning of the input field) instead of the middle, while still keeping my placeholder text centered?
<input type="text" name="input_query" id="input_query" autofocus style="text-align: center; width: 100%" placeholder="Describe what's happening in your photo" autoplete="off"/>
Share
Improve this question
edited Apr 30, 2018 at 4:56
Smokey Dawson
9,24022 gold badges85 silver badges162 bronze badges
asked Apr 30, 2018 at 3:50
user6004404user6004404
2 Answers
Reset to default 9Use ::placeholder
to apply CSS to the placeholder only:
input {
width: 100%
}
input::placeholder {
text-align: center;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autoplete="off"/>
If you want the cursor to appear at the beginning of the placeholder, you can do something similar, though it's pretty weird and isn't centered once the user starts typing:
input {
width: 65%;
padding-left: 35%;
}
<input type="text" autofocus placeholder="Describe what's happening in your photo" autoplete="off"/>
this is if you want placeholder to be in the middle but text to start from left. hope that works for you
#input_query{
text-align: left;
}
::-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" name="input_query" id="input_query" autofocus style=" width: 100%" placeholder="Describe what's happening in your photo" autoplete="off"/>
本文标签: javascriptHow to position HTML input cursor at beginning of centered placeholderStack Overflow
版权声明:本文标题:javascript - How to position HTML input cursor at beginning of centered placeholder - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744270110a2598140.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论