2015-03-31 50 views

回答

1

有办法用CSS来做到这一点,但他们都不是真正有效的,也有用户简单的方法来解决CSS只方法。但是这里有一个例子反正使用CSS:

你的HTML:

<div id="con"> 
    <input name="name" type="text" value="Text input" /> 
    <span id="overlay"></span> 
</div> 

你的CSS:

#con { 
    width: 300px; 
    height: 50px; 
    position: relative; 
} 
#con input[type="text"] { 
    position: relative; 
    top: 15px; 
    z-index: 1; 
    width: 200px; 
    display: block; 
    margin: 0 auto; 
} 
#con #overlay { 
    width: 300px; 
    height: 50px; 
    position: absolute; 
    top: 0px; 
    left: 0px; 
    z-index: 2; 
    background: rgba(155,0,0, .5); 
} 

Example fiddle

如前所述,jQuery的将是一个更可靠的解决方案到这个特定的问题。