How can I make a TextArea 100% width without overflowing when padding is present in CSS?

Eric Schoonover picture Eric Schoonover · Nov 7, 2008 · Viewed 436.1k times · Source

I have the following CSS and HTML snippet being rendered.

Is the problem is that the text area ends up being 8px wider (2px for border + 6px for padding) than the parent. Is there a way to continue to use border and padding but constrain the total size of the textarea to the width of the parent?

Answer

Piet Bijl picture Piet Bijl · Nov 11, 2010

Why not forget the hacks and just do it with CSS?

One I use frequently:

.boxsizingBorder {
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;
}

See browser support here.