Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile and textarea rows

So, I'ld like to display a textarea on just 1 row.

But jQuery Mobile doesn't think so... Whatever value I set in the rows attribute, it always is 2 rows height...

Would it have any solution ?

like image 261
Axiol Avatar asked Mar 15 '12 17:03

Axiol


People also ask

Which attribute is used in defining rows in textarea?

HTML | <textarea> rows Attribute. The HTML textarea rows Attribute is used to specify the number of visible text lines for the control i.e the number of rows to display. It also specifies the visible height of the Textarea.

How set textarea size in HTML?

We can set the size for the text area by using rows and columns. rows*columns will be the size of the text area. For columns, we have to use the cols keyword.

How do you auto expand textarea?

It can be achieved by using JavaScript and jQuery. Method 1: Using JavaScript: To change the height, a new function is created which changes the style property of the textarea. The height of the textarea is first set to auto. This value makes the browser set the height of an element automatically.

How do I fit textarea to text?

To automatically resize textarea height to fit the text, we can use the Element. scrollHeight , which gives the actual height of an element's content, including overflow. It is the minimum height the element would require to fit all the content on the screen.


2 Answers

The jQuery Mobile CSS sets a specific height for textarea elements:

textarea.ui-input-text {
    height : 50px;

    -webkit-transition : height 200ms linear;
       -moz-transition : height 200ms linear;
         -o-transition : height 200ms linear;
            transition : height 200ms linear;
}

You can create your own rule to override this height to something more single-line:

.ui-page .ui-content .ui-input-text {
    height : 25px;
}​

Demo: http://jsfiddle.net/mEs8U/

like image 96
Jasper Avatar answered Sep 29 '22 04:09

Jasper


You can also use max-height to set the autogrowing limits to textarea.

textarea.ui-input-text {
    max-height : 100px;
}
like image 22
Ankur Gupta Avatar answered Sep 29 '22 02:09

Ankur Gupta