I'm using contenteditable divs instead of input elements, because they are more flexible when it comes to styling within the input box. I'm just wondering if there's a way to make the input look like an input element with its type set to password, like so:
<input type='password'>
I hope that is clear enough. Thanks.
You will have to find out the browser specific CSS settings for mozilla and co., but in webkit it looks like this. Also you need to add the keypress handler via javascript for it.
But anyway, password fields are just combined elements with
element.innerHTML="yourpassword"
andelement.innerText="•••••••"
You could do this with javascript too and fill
innerText
with"•"
.To get rid of password remember, I treated the password as input field, and "blur" the text typed.
It is less "safe" than a native password field since selecting the typed text would show it as clear text, but password is not remembered. It also depends on having Javascript activated.
I came across this question as I was trying to imitate a password input as well, but overlaying another div with
•
s wasn't an option for me, since I wanted it to work without JavaScript, too.Then there's
text-security: disc
, but there isn't enough support for that as of this moment.So what I've done is create a font on FontStruct in which all Latin characters (including the diacritic ones) look like a
•
.Here is a link to the file on my Dropbox.
When using this, just add this in your css file
Then to use it, simply apply
font-family: 'password'
to your element.P.S. If the Dropbox link is down and you happen to have it downloaded, feel free to replace the link. Otherwise just give this answer a comment
Here's my solution. It's not perfect (it only handles additional/deleted characters at end), but it's pretty short:
html:
JavaScript:
JavaScript to retrieve password: