2012-07-20 96 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

相關問題