I want to make input box which wraps text and shrink to it's size, what property should I use?
I tried to scale it using width: auto but it's no use.
I want to make input box which wraps text and shrink to it's size, what property should I use?
I tried to scale it using width: auto but it's no use.
The only way to do this is using contenteditable
with a div
element, otherwise you have to rely on JavaScript
const myinput = document.querySelector('.myinput');
document.querySelector('#mybutton').addEventListener('click', () => {
alert(myinput.innerHTML);
})
.myinput {
display: inline-block;
padding: 5px 10px;
border-radius: 3px;
background-color: #e5e5e5;
min-width: 10px;
max-width: 400px;
height: 22px;
line-height: 22px;
font-size: 16px;
white-space: nowrap;
overflow: hidden;
}
<div contenteditable="true" class="myinput"></div>
<button id="mybutton">Get input value</button>