The textarea's rows
attribute does not match the number of lines in Firefox. For instance:
<textarea rows=4 cols=40>
1
2
3
4
this line is visible in FF
</textarea>
Example: http://jsfiddle.net/Z7zXs/6/
How can I fix this issue? The textarea should only display 4 lines (instead of 5) for rows=4
.
I've had the same problem once and i couldn't use CSS, so JavaScript is the only way: Here's the Mootools and jQuery ways to do this:
Mootools:
jQuery:
It will check if the browser is firefox, if it is, it will check if the rows have been corrected already, and if not they will get fixed.
Firefox always adds an extra line after the textfield. If you want it to have a constant height, use CSS, e.g.:
http://jsfiddle.net/Z7zXs/7/
EDIT: You can also use the
@-moz-document url-prefix
CSS extension to target only the Firefox browser. ExampleYou can fix the height by using JavaScript (or hard-code a height of
4x1.2 = 4.8em
).Example (JQuery), fix the issue for each textarea:
The value of the
line-height
CSS property equals the height of each line ("row"). So, when you've definedrow
, this code will fix the height.When the
rows
attribute is not set, the code will have a look at the default value (.prop("rows")
).There are lot of answers but wasn't suitable for me:
height: 5em;
) is not flexible enoutgh because it completely overridesrows
attributeThere is a "bug": TEXTAREA incorrectly applying ROWS= and COLS=
So here is my solution:
FF adds height to the TextArea to reserve place for scroll-bars.
I don't need horizontal scroll bar so it helps with fixing the issue: following css rule can be added to textarea:
Here is example. It works even with
rows=1
.