So, i have troubles with a textarea now, and i cant make it resize to a content width... Ive found a long and detailed answer about content height, and it works !! but not having the content width on it...
This is that post: Creating a textarea with auto-resize
BUT, my issue isnt solved, i need the width to resize too. Considering max and min widths.
This is the example code:
$("textarea").each(function () {
this.setAttribute("style", "height:" + (this.scrollHeight) + "px;");
}).on("input", function () {
this.style.height = 0;
this.style.height = (this.scrollHeight) + "px";
});
$("textarea").trigger("input");
textarea{
border: 1px solid black;
min-width: 50px;
max-width: 300px;
width: auto;
}
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.3.min.js"></script>
<textarea>this is my normal content, and it has to consider this content to be as long as the max-width</textarea>
<textarea>this is my normal content, should be consider</textarea>
<textarea>this is my min content</textarea>
Also, this is how i want them to be: