Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea max-width

Tags:

html

css

textarea

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.

like image 339
no1lov3sme Avatar asked Jan 14 '15 09:01

no1lov3sme


People also ask

How do I limit the width of a textarea?

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 increase the width of a textarea in HTML?

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: .

How do you define the size of a textarea element?

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).


3 Answers

Use:

textarea { 
   /* will prevent resizing horizontally */
   resize:vertical;
}
like image 161
Bhojendra Rauniyar Avatar answered Oct 14 '22 05:10

Bhojendra Rauniyar


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%;
}
like image 38
user6297197 Avatar answered Oct 14 '22 04:10

user6297197


For default the text area is re sizable. If you want to increase the element width, you can do it by

HTML

<textarea rows="4" cols="50">Content here</textarea>

CSS

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.

like image 43
Naveen - நவீன் Avatar answered Oct 14 '22 03:10

Naveen - நவீன்