I'm having problem with textarea max-width, I need it to not exceed .table-cell.two width when resized, on this example:
JSfiddle example
HTML:
<div class="wrapper">
<div class="table">
<div class="table-cell one">
<p>small cell</p>
</div>
<div class="table-cell two">
<p>textarea cell</p>
<textarea></textarea>
</div>
</div>
CSS:
textarea {
max-width: 100%;
}
.wrapper {
width: 500px;
}
.table {
display: block;
width: 100%;
}
.table-cell {
display: table-cell;
background: #E2D8C1;
vertical-align: top;
padding: 10px;
}
.table-cell.two {
width: 100%;
background: #DAC082;
}
.table textarea {
max-width: 100%;
width: 100%;
height: 100px
}
Please do not advise using javascript, needed a pure css solution.
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.
You need to define width of the div containing the textarea and when you declare textarea , you can then set . main > textarea to have width: inherit . Note: .
The size of a text area is specified by the <cols> and <rows> attributes (or with CSS). The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the text area will be submitted).
Use:
textarea {
/* will prevent resizing horizontally */
resize:vertical;
}
I have this problem too. The solution is very simple but i spend few hours for experiments... Use this two parameters at the same time in textarea element class/#element style definition (90% 30% are example values) :
.textarea {
width:90%;
max-width:90%;
max-height:30%;
}
For default the text area is re sizable. If you want to increase the element width, you can do it by
<textarea rows="4" cols="50">Content here</textarea>
max-width: 300px;
max-height:300px
Demo on jsfiddle
In your case you want to fix the <textarea>
size when the parent does not have a fixed size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With