Adding or creating a label in input element


#1

This code works great in IE, in that when you click in it the sample email address goes away and if you click outside the input box the sample reappears.

<input type="text" size="30" name="user" placeholder="Sample@example.com">

It doesn't work in Chrome or FF.

Is there a better solution using CSS that would work in all? I can't seem to find one in my research.

Thank you.


#2

You can hide the ::placeholder pseudo element of the focused input like

input:focus::placeholder {
  color: transparent;
}

Technically you'd need prefixes for MS browsers, but if that's default there anyway this is of course not necessary.


#3

Hi @javascript7,
I have just tried in FF and Chrome and it works for me... please bear in mind that if there is already a value set in the input the placeholder will not appear when you click outside or remove the focus.
I'm puzzled that you're getting this issue because placeholder is supported in FF and Chrome.
Perhaps if you sent us a link we would be able to help you further.

All the best


#4

That did the trick!!

Thank you for that, I appreciate it.


#5

Thank you for your reply. The comment before you did the trick.


closed #6

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.