2016-11-06 39 views
0

如何使我的輸入框長度相對於文本的數量?如何在文本數量後輸入大小輸入

<div class="kontakt"> 
       <h2>Kontakt oss</h2> 
       <p>Hei! Jeg heter <input type="text" name="navn" placeholder="navn">, og jeg lurer på følgende:</p> 

CSS:

.kontakt { 
margin-top: 4%; 
font-size: 80%; 
text-align: center; 
} 
.kontakt input{ 
    border:none; 
    border-bottom: 1px solid black; 
    background:none; 
    color:white; 
    opacity: 0.7; 
    text-align: center; 
    size: relative; 
} 
+3

http://stackoverflow.com/questions/3392493/adjust-width-of-input-field-to-its-input –

+1

的可能重複做了一些搜索和couldn」找不到任何東西,但這正是我所尋找的,所以謝謝你! –

回答

0

這將幫助你:

adjustable text area


$('input[type="text"]').keypress(function(e) { 
    if (e.which !== 0 && e.charCode !== 0) { // only characters 
     var c = String.fromCharCode(e.keyCode|e.charCode); 
     $span = $(this).siblings('span').first(); 
     $span.text($(this).val() + c) ; // the hidden span takes 
             // the value of the input 
     $inputSize = $span.width() ; 
     $(this).css("width", $inputSize) ; // apply width of the span to the input 
    } 
}) ; 
相關問題