This is done automatically for every browser except Chrome.
I'm guessing I have to specifically target Chrome.
Any solutions?
If not with CSS, then with jQuery?
This is done automatically for every browser except Chrome. I'm guessing I have to specifically target Chrome. Any solutions? If not with CSS, then with jQuery? |
|||||||||||||||||||||
|
EDIT:
|
|||||||||||||||||||||
|
Firefox 15 and IE 10+ also supports this now. To expand on Casey Chu's CSS solution:
|
|||||||||||||||||||||
|
Here is a CSS-only solution (for now, only works in WebKit):
|
|||||||||||||||||
|
have you tried placeholder attr?
-EDIT- I see, try this then:
Test: http://jsfiddle.net/mPLFf/4/ -EDIT- Actually, since placeholder should be used to describe the value, not the name of the input. I suggest the following alternative html:
javascript:
css:
Test: |
|||||||||||||||||||||
|
To augment @casey-chu's and pirate rob's answer, here's a more cross browser compatible way:
|
|||||
|
Toni's answer is good, but I'd rather drop the
Note that
|
|||||||||
|
I like to package this up in the name space and run on elements with the "placeholder" attribute...
|
|||||
|
To further refine Wallace Sidhrée's code sample:
This ensures that each input stores the correct placeholder text in the data attribute. |
|||||
|
I like the css approach spiced with transitions. On Focus the placeholder fades out ;) Works also for textareas. Thanks @Casey Chu for the great idea.
|
|||
|
Using SCSS along with http://bourbon.io/, this solution is simple, elegant, and works on all web browsers:
Use Bourbon ! It's good for you ! |
|||
|
Sometimes you need SPECIFICITY to make sure your styles are applied with strongest factor So please consider adding styles prefixed with the id of the app container
|
||||
|
This piece of CSS worked for me:
|
|||||
|
Building on @Hexodus and @Casey Chu's answers, here is an updated and cross-browser solution that leverages CSS opacity and transitions to fade the placeholder text out. It works for any element that can use placeholders, including
|
|||||
|
HTML:
jQuery:
|
|||||
|
Demo is here: jsfiddle Try this :
|
||||
for input
for textarea
|
|||
|
|
|||||
|
For a pure CSS based solution:
Note: Not yet supported by all browser vendors. Reference: Hide placeholder text on focus with CSS by Ilia Raiskin. |
||||
|
|
|||
|
Besides all of above,I have two ideas. You can add an element that imitates the palceholder.Then using javascript control the element showing and hiding. But it is so complex,the other one is using the brother's selector of css.Just like this:
23333,I have a poor English.Hope solve your problem. |
|||||
|
try this function: +It Hides The PlaceHolder On Focus And Returns It Back On Blur +This function depends on the placeholder selector, first it selects the elements with the placeholder attribute, triggers a function on focusing and another one on blurring. on focus : it adds an attribute "data-text" to the element which gets its value from the placeholder attribute then it removes the value of the placeholder attribute. on blur : it returns back the placeholder value and removes it from the data-text attribute
you can follow me very well if you look what's happening behind the scenes by inspecting the input element |
||||
|