John Doe
John Doe

Reputation: 3691

I have a textarea that won't have 100% in width when I set it in CSS or plain HTML?

How can I set a textarea to 100% in width? it dosn't work when I say: textarea {width: 100%} in css.

Upvotes: 0

Views: 526

Answers (4)

Lea Verou
Lea Verou

Reputation: 23907

There are several ways to fix this issue:

  • Give the parent element a padding-right equal to the accumulated border-width and padding of the textarea (supported by all browsers)
  • Use the box-sizing property 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)

Upvotes: 2

Marcel
Marcel

Reputation: 28097

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.

Upvotes: 0

orlp
orlp

Reputation: 117926

You are forgetting a semi-column:

textarea {
    width: 100%;
}

Upvotes: 0

Josh M.
Josh M.

Reputation: 27831

Make sure all of the parent elements have an appropriate width - post more information if that doesn't help.

Upvotes: 0

Related Questions