Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the width and height of a textarea using CSS?

Tags:

Here is my css:

.editor-field textarea {     width : 400;     height : 100px; } 

Here is the markup from my view:

        <div class="editor-field">             @Html.EditorFor(model => model.Visit.BehavioralObservations)             @Html.ValidationMessageFor(model => model.Visit.BehavioralObservations)         </div> 

And here is the annotation of my model showing the MultilineText attribute:

    [DisplayName("Behavioral Observations")]     [DataType(DataType.MultilineText)]     public string BehavioralObservations { get; set; } 

Why can't I set the width of this textarea? I can adjust the height in my CSS and it looks correct (verified with Chrome Developer tools) but the width doesn't change. Chrome says the width is an invalid property value and has a strike-through applied to the property along with a yellow triangle displayed adjacent to the property.

FYI, this is not limited to Chrome. IE8 has the same issue.

Thoughts? How do I fix this? Thanks!

like image 646
Joe Avatar asked May 18 '12 19:05

Joe


People also ask

How do you change the size of textarea in CSS?

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). The id attribute is needed to associate the text area with a label.

How do I change the width and height of a 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.

How make textarea responsive CSS?

Try textarea {max-width:95%;} - it will always fit your display. Show activity on this post. I set the number of columns to slightly greater that the width of the div on a large screen and as the screen gets smaller it acts responsive to the screen size.


1 Answers

try to use TextAreaFor helper method and set cols and rows html property

Sample

@Html.TextAreaFor(model=>model.MyMultilineText, new {rows="6", cols="10"}) 

I Hope this help. Regards.

like image 144
vfabre Avatar answered Sep 21 '22 23:09

vfabre