I’m trying to build a jQuery plugin that fakes the HTML5 placeholder
attribute (like What is the most accurate way to emulate the "placeholder" attribute in browsers that don't support it natively?). To do this I’m inserting a <span>
before the appropriate <input>
or <textarea>
and duplicating the styling.
Unfortunately, I’ve discovered that browsers magically place the text differently in <input>
s than <span>
s or <textarea>
s, as demonstrated by http://jsfiddle.net/63zcD/1/—the text is vertically centered in the <input>
, even though Web Inspector says the styling is identical across all three. The effect appears in Safari, Chrome, and Firefox.
Tricks that haven’t worked:
vertical-align: middle;
,vertical-align: text-bottom;
display: inline-block;
Twitter’s login page fakes the placeholder
attribute, but they get around this problem by wrapping the <span>
and <input>
/<textarea>
in a containing <div>
and manually styling the <span>
for a visual match, which isn’t an option for a plugin that needs to run automatically.