Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Force textarea to ocuppy all available area

Tags:

html

css

I'm working on a form with an horizontal layout:

 <div id="container">
  <label for="ta">description</label>
  <textarea id="ta" name="ta" cols="50" rows="10"></textarea>
 </div>

The problem is that what I want is the textarea take up all available space that the label leaves in the same line. If I try with width=100% it jumps to the next line:

div * {
    vertical-align: middle;
}
textarea {
    width: 100%;
    height: 300px;
}

Any idea to implement it without assign a fixed space to each tag?

like image 678
Ivan Avatar asked Jun 24 '11 17:06

Ivan


People also ask

How do I autosize textarea?

</textarea> Now add an attribute to tell the element to automatically resize on input, i.e. `<textarea autosize>`. <textarea autosize>Will auto resize.

How make textarea responsive CSS?

Use the CSS3 resize Property. You can use the CSS3 resize property to remove or turn-off the default horizontal and vertical resizable property of the HTML <textarea> element. This property will also hide the resizing handle at the bottom-right corner of the textarea.

How do I restrict textarea size in HTML?

In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.

How do I adjust textarea in HTML?

The cols attribute specifies the visible width of a text area. Tip: The size of a text area can also be set by the CSS height and width properties.


2 Answers

Like this? http://jsfiddle.net/4QbMr/

<div id="container">
    <label for="ta">description</label>
    <div class="twrap"><textarea id="ta" name="ta" cols="50" rows="10"></textarea></div>
</div>

label {
    float: left
}
.twrap {
    overflow: hidden;
    padding: 0 4px 0 12px
}
textarea {
    width: 100%;
    height: 300px;
}
like image 188
thirtydot Avatar answered Nov 15 '22 05:11

thirtydot


For table-like behaviour with CSS, display: table is your friend:

#container {
    display: table;
    width: 100%;
}
#container label, #container textarea {
    display: table-cell;
    vertical-align: top;
}
#container textarea {
    width: 100%;
    height: 300px;
}

Note that if you specify cols and rows attributes, they will override your CSS.

like image 31
robertc Avatar answered Nov 15 '22 05:11

robertc