I must be missing something obvious here, but can’t work it out. In the html below, which is a simple textarea inside a fixed-width DIV, I want to make the textarea fit itself width-wise within the width of the div, with a nice little margin around the outside.
The result I want is this:
But what I’m getting is this:
I’ve tried various combinations of margin & padding for both the div and textarea, but it doesn’t want to fit. Can someone advise me as to what the correct css should be, so the textarea resizes to the width of the div, with a 5px margin around the edge?
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The problem is likely that you’ve set the text area width to 100% and also added padding. You can try removing the padding, but that’s often not ideal. Is it common that the parent element of the text area changes in width? If not, skip the % width and set it statically.
Is it common that the parent element of the text area changes in width? If not, skip the % width and set it statically.
Thanks, but yes it does in a way.. I wanted to just set a single style to apply to all textareas, so wherever they appear, they end up being as big as their container allows. So it will be various widths at various times. Regardless, I thought dynamic resizing was easy to do in CSS, but the content-box model makes it damn difficult.
Thank god CSS3 is formalising border-box as an options. I can see lots of people wanting to use it for web apps. Apps are often different animals to normal pages, and we need good design tools to make them app-like. W3C is on another planet in that respect.