I have an input text like the following:
<input type="text" placeholder="mm/dd/yyyy" style="text-align:center"/>
The placeholder is correctly shown centered, but when I focus on the field, the cursor is also at the center of the text field, and I want it to be at the left of the placeholder. How can I align the cursor only?
You can use the :focus
selector.
You probably also want to use ::placeholder
selector so that the placeholder doesn't move.
input, input::placeholder {
text-align: center;
}
input:focus {
text-align: left;
}
<input type="text" placeholder="mm/dd/yyyy"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With