How to make textarea fill the width of its parent width?

Viewed 16119

Given that we don't know the div's width beforehand?

My idea: Calculate the div 's width with JS, find a way to convert it to cols and the apply the css to the textarea onthe fly. But perhaps there 's no need to reinvent the wheel?

Thank you.

2 Answers

I advise flex over width: 100%, as 100% often does not account for borders, causing horizontal scrolls to appear.

<div style="display: flex">
    <textarea style="flex: 1"></textarea>
</div>
Related