2016-11-06 9 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 
    } 
}) ; 
関連する問題