0

I am creating a two-column layout by having one div floating left (with a width of almost 50%) and another div floating right. Inside these divs I am displaying a textarea. This works fine in principle and nicely adjusts the width of the columns to the available width.

However, when someone uses the browser's textarea resizing function (e.g. in Firefox) to change the size of the textarea, the div does not adjust. The result of this is that the text area is resized, but extends outside the div (or just becomes cut off).

Can I fix this somehow?

MWE:

    <div style="overflow: hidden;">
     <div style="float: left; width: 40%; background: red; padding: 1em;">
      <textarea style="width: 100%">left</textarea>
     </div>
     <div style="float: right; width: 40%; background: green; padding: 1em;">
      <textarea style="width: 100%">right</textarea>
     </div>
    </div>
Nils
  • 1,936
  • 3
  • 27
  • 42

2 Answers2

1

You can only permit the vertical resizing to avoid your problem.

CSS

textarea { resize:vertical; }

DEMO HERE

If you want to disble the resizing do this:

CSS

textarea { resize:none; }

If you want to have the resizing and expand the div you should use min-heightinstead width:

HTML

<div style="overflow: hidden;">
    <div style="float: left; min-width: 40%; background: red; padding: 1em;">
        <textarea style="width: 100%">left</textarea>
    </div>
    <div style="float: right; min-width: 40%; background: green; padding: 1em;">
        <textarea style="width: 100%">right</textarea>
    </div>
</div>

DEMO HERE

Luís P. A.
  • 9,524
  • 2
  • 23
  • 36
1

You can disable the horizontal resizing of text area

textarea {
  resize: vertical; /* you can resize vertically, but not horizontal */
}
Arun Kumar M
  • 1,633
  • 1
  • 15
  • 26