Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder doesn't disappear when input field in focus

Tags:

html

css

The placeholder value of each input field on a form should disappear when the user selects the field, but it does not. Doctype is HTML5.

http://dailyspiro.com/index.html

<input required type="text" name="user-first-name" id="user-first-name" placeholder="First Name" class="text ui-widget-content ui-corner-all decorative-icon icon-user" />
like image 638
Ben Davidow Avatar asked Dec 25 '22 11:12

Ben Davidow


2 Answers

CSS

input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* Firefox 18- */
input:focus::-moz-placeholder { color:transparent; } /* Firefox 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* oldIE ;) */

see here http://sridharkatakam.com/make-search-form-input-box-text-go-away-focus-genesis/

like image 192
chiliNUT Avatar answered Feb 27 '23 07:02

chiliNUT


You can achieve the same thing with a little js. Not sure if you're looking or a plain HTML. @chiliNUT's option should work for you. Anyway, since I'm not totally clear on what you want...

Here are 2 options:

<input required type="text" name="user-first-name" id="user-first-name" class="your list of class names" placeholder="First Name" onfocus="if(this.value == 'First Name') { this.value = ''; }" value="First Name"/>

<input required type="text" name="user-first-name" id="user-first-name" class="your list of class names" onfocus="if(this.value == 'First Name') { this.value = ''; }" value="First Name"/>

And the obligatory fiddle.

like image 26
SwankyLegg Avatar answered Feb 27 '23 08:02

SwankyLegg