Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox stretch textarea in column

Tags:

html

css

flexbox

I am trying to get this textarea in a 2 column layout to stretch to fill the empty space. So the right column is variable height and I would like the textarea in the left column to stretch to fill the empty space. I have tried using align-items: stretch on the parent as well as setting the height to 100% on the textarea and I can't seem to get it to grow to fill the space.

Here is the HTML

<div class="row">
    <div class="left">
        <h1>Stuff</h1>
        <textarea></textarea>
    </div>
    <div class="right">
        <h1>Preview</h1>
        <div class="content"></div>
    </div>
</div>

Here are the styles

.row{
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: space-between;
}

.row > div{
  flex: 0 0 50%;
  max-width: 50%;
}

textarea{
  height: 100%;
}

.content{
  height: 500px;
  background-color: green;
}

Here is a plunkr

I understand the need for vendor prefixes and all that so you don't need to get into that. This is just a simplified version of my code to demonstrate the problem I am having.

like image 461
Kevin F Avatar asked Jun 26 '15 20:06

Kevin F


People also ask

How do I fix the text area size?

To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.

How do I make textarea auto grow?

Now to make the textarea autogrow, you must hide the scrollbar and adjust the height of the textarea to the height of the contents in it. This adjustment of height should occur whenever the height of the contents change. scrollHeight of the textarea will give you the height of the entire content of the textarea.

What property and value are used to display flex items in a column?

The flex-basis property The initial value of this property is auto — in this case the browser looks to see if the items have a size. In the example above, all of the items have a width of 100 pixels and so this is used as the flex-basis . If the items don't have a size then the content's size is used as the flex-basis.


1 Answers

Make .left a flexbox, only allowing the textarea to grow:

.left {
  display: flex;
  flex-direction: column;
}

.left > textarea {
  flex: 1;
}

Plunker

like image 144
Rick Hitchcock Avatar answered Sep 17 '22 08:09

Rick Hitchcock