【问题标题】:How to size input after text amount如何在文本量后调整输入大小
【发布时间】:2017-03-19 20:47:20
【问题描述】:

如何使我的输入框长度相对于其中的文本量?

<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;
}

【问题讨论】:

标签: html css web


【解决方案1】:

这将对您有所帮助:

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
     }
}) ;

【讨论】:

    【解决方案2】:

    你可以试试这个:-

    style='width:20em'
    

    链接:-Input size vs width

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多