2012-07-20 99 views
1

我想将输入字段风格化为Twitter上的授权。我有以下的HTML标记:如何在Twitter上设置输入字段的样式?

<input hint="hint" name="name" type="text"> 

我需要改变包含在焦点属性hint文本的不透明度。我该怎么做?

+0

利用预留= “你的暗示”,但支持现代浏览仅 – SVS 2012-07-20 09:12:26

+1

@SVS - 有许多[polyfills(HTTPS:/ /github.com/jamesallardice/Placeholders.js),这将允许'placeholder'属性在旧版浏览器中工作,但我认为OP正在寻找比原生占位符更多的东西。 – 2012-07-20 09:13:13

+0

我需要使用'提示'。如果我使用'占位符',它将被隐藏在焦点上...... – 2012-07-20 09:14:14

回答

1

好吧,这里是你想要什么:http://jsfiddle.net/surendraVsingh/NLrRC/16/

HTML

<div class="container"> 
<input type="text" /> 
<span>Username or email</span> 
</div>​ 

CSS

.container{position:relative; display:inline-block; overflow:hidden;} 
.container input{position:relative; z-index:98;} 
.container span{position: absolute; z-index:99; color:#ccc; left:5px; top:3px; font-size:11px;} 

jQuery的(更新:对事件的内容清除输入的拆除错误)

$('input').keyup(function(){ 
    $(this).next().css('z-index', '0'); 
}); 
$('input').blur(function(){ 
    if($('input').val()=== ''){ 
    $('input').next().css('z-index', '99'); 
    } 
}); 
+0

嘿!使用这个更新的答案它不会清除聚焦输入。 – SVS 2012-07-20 11:38:25

0

试试这个

input[hint="hint"]:focus{ 
     opacity: .4; 
    } 
+0

它不起作用... – 2012-07-20 09:43:12

相关问题