Automatically stretch or shrink `` depe

2019-05-26 07:39发布

问题:

I have two <textField> one by one. Is possible to automatically stretch or shrink them depending on text length? The only attribute which hit my eyes, was the isStretchWithOverflow but cause that one text is covering another - that is not what I meant. Anybody helps? Is it even possible?

回答1:

I assume you are talking about stretch vertically.

In that case isStretchWithOverflow is exactly what you need.

The second <textfield> covered by first one is because the position setting. You probably has it setting to Fix, so it dose not move while first one stretched. Change the position setting of second <textfield> to Float should works.



回答2:

I don't believe this is possible using pure HTML/CSS. However, you could do it by using Javascript. One way would be to bind a keypress event handler to your input which updates its width.

If you use JQuery, something like:

 $(yourInput).keypress(function(){
     $(this).css("width", $(this).val().length * 5);
 });

should do the trick (although you'll probably want to adjust the calculation; I have no idea if 5px per character is too much or too little).