I need to hide the text box blinking cursor in CSS / Javascript.
Is it possible?
You could set a maxlength
on the textbox and then use text-indent
to move the cursor back more characters than the maxlength.
For example, you could set maxlength=20
and then for the text box set text-indent: -20em
that way the text starts out of the box's boundaries and can't ever come into view.
Here is my solution from another question, that I answered already:
https://stackoverflow.com/a/23472096/1806628
The basic idea is, that the cursor's color is the same as the text's color. So the first thing you do is make the text transparent, thus taking the cursor away with it. Then you can make the text visible again with a text shadow.
input[type="text"]{ color : transparent; text-shadow : 0 0 0 #000; } input[type="text"]:focus{ outline : none; }
Warning:
It does not seem to work under iOS 8. (Thanks @Altaveron for the info)
Another idea of my is a bit more hacky and requires javascript.
HTML and CSS part:
You make 2 input fields and position one exactly on top of the another with z-index, etc. Then you make the top input field completely transparent, no focus, no color, and alike. You need to set the visible, lower input to disabled, so that it only shows the content of the above input, but not actually works.
Javascript part:
After all the above you sync the two inputs. On keypress or on change you copy the contents of the higher input to the lower.
Summing all the above: you type in an invisible input, and that will be sent to the backend when the form submitted, but every update of the text in it will be echoed into the lower visible, but disabled input field.
This is pretty old, but I was just dealing with a similar issue. For browsers that support it (meaning, not IE8), you can set the color of the input element to be the same as its background (probably white), and then the cursor will be invisible.
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