Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Justify Text in a HTML/XHTML TextArea

I am currently trying to justify text in a textarea, unfortunately the CSS:

text-align: justify;

Doesn't work on the text like center, left and right do. I've tried this in both Firefox 3 and IE 7 with no luck.

Is there any way around this?

like image 587
Matt Avatar asked Jan 09 '09 04:01

Matt


People also ask

How do you align text in xhtml?

Type text-align:. 2. Type left to align the text to the left. Or type right to align the text to the right.

How do I align justify text in HTML?

In order to suggest that some text be justified on both sides, you can use the align="justify" attribute in HTML, or the text-align:justify declaration in CSS, or both.

Can we use value attribute in textarea?

<textarea> does not support the value attribute.


2 Answers

I dealt with same issue and found out very stupid solution. Make sure that the text to be displayed falls within the start and end tag elements in the same line and not in the next line

<textarea  name="description" readonly="readonly" rows="4" cols="66">Text aligned toward left</textarea>

and not like

<textarea  name="description" readonly="readonly" rows="4" cols="66">
Text aligned toward left
</textarea>
like image 174
shweta Avatar answered Oct 02 '22 09:10

shweta


Depending on your target browser... this solution works in Chrome. It does not work work in Firefox however... but I'll post it anyway.

In addition to setting text-align: justify, you must also set white-space: normal.

    textarea {
        text-align: justify;
        white-space: normal;
    }

JSFIDDLE: http://jsfiddle.net/cb5JN/

like image 21
Norman Breau Avatar answered Oct 02 '22 07:10

Norman Breau