Justify Text in a HTML/XHTML TextArea

2019-01-26 06:10发布

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?

7条回答
Animai°情兽
2楼-- · 2019-01-26 06:53

For me (in Firefox), this code works perfectly:

textarea{
    resize: none;
    text-align: justify;
    white-space: pre-line;
    -moz-text-align-last: left;
    text-align-last: left;
}
查看更多
Rolldiameter
3楼-- · 2019-01-26 06:58

i dont think this is possible in the html textarea element. you might be able to use some sort of wysiwyg editor (editable div). ie. fckeditor

查看更多
你好瞎i
4楼-- · 2019-01-26 06:59

Using a common div with contenteditable="true" worked in my case. Doesn't work for most mobile browsers though.

<div contenteditable="true">Some content</div>
查看更多
小情绪 Triste *
5楼-- · 2019-01-26 07:00

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>
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-26 07:04

It works fine on Chrome, but not on IE.

text-align: justify; white-space: normal;

查看更多
We Are One
7楼-- · 2019-01-26 07:05

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/

查看更多
登录 后发表回答