我的自定义占位符有一个输入字段。由于IE和Mozilla问题,我自定义了它。
因此,基本上,输入字段具有绝对定位的<span>
元素,以使其完全适合输入字段。
但是,当我专注于输入字段时,焦点将转到span元素。我尝试使用,z-index
但是没有用。请帮忙。我只希望光标集中在输入字段而不是span元素上。
#placeholder {
position: absolute;
top: 12px;
left: 0;
padding-left: 10px;
font-size: 11px;
}
<input type="text" style="position: relative;">
<span id="placeholder">Type and Hit Enter to Search...</span>
只需使用label
包装两个元素即可。您还可以调整一些CSS以使跨度消失在焦点上:
label {
position:relative; /*Make the span positioned relatively to the label*/
}
#placeholder {
position: absolute;
top: 4px;
left: 0;
padding-left: 5px;
font-size: 11px;
}
/*On focus change the z-index*/
input:focus + #placeholder {
z-index: -1;
}
<label>
<input type="text">
<span id="placeholder">Type and Hit Enter to Search...</span>
</label>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句