How can I set a textarea to 100% in width? it dosn't work when I say: textarea {width: 100%} in css.
4 Answers
There are several ways to fix this issue:
- Give the parent element a
padding-rightequal to the accumulated border-width and padding of the textarea (supported by all browsers) Use the
box-sizingproperty to include border and padding when setting width:-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;(supported by IE8+ and all other browsers)
Comments
It does work but a parent element is probably just restricting the width of your <textarea> so without seeing your code there's no specific answer to your question.
2 Comments
John Doe
friendsconnect.org/dashboard/dashboard.html If you look at it now, do you know why the textarea seems to be longer than the parent DIV? I set the two textareas to 100% but they go outside the div? Why should I be doing differently
Marcel
@Pete Allport: Adding padding and border to the
<textarea> makes it wider than 100%. You'll need to give it an absolute value like 418px instead.You are forgetting a semi-column:
textarea { width: 100%; } 4 Comments
thirtydot
It's not required for the last rule. See pretty much every answer I've written on this site.
Amadan
@thirtydot: this does not make a difference here, but I disagree: even though it is totally not required, it is good style, making maintenance a bit easier (unless you're optimising bytes). (Although I'm the last one to talk, I often omit curlies on one-line
if statements blush )thirtydot
@Amadan: It depends on how you look at it; because I always omit that last semicolon, I'm always aware, so it doesn't affect the difficulty of maintenance for me in the slightest, whether I'm looking at CSS that is omitting it or not. ;)
John Doe
friendsconnect.org/dashboard/dashboard.html If you look at it now, do you know why the textarea seems to be longer than the parent DIV? I set the two textareas to 100% but they go outside the div? Why should I be doing differently