Justify Text in a HTML/XHTML TextArea

前端 未结 7 1310
借酒劲吻你
借酒劲吻你 2020-12-10 13:04

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

text-align: justify;

Doesn\'t work on the text like center, lef

相关标签:
7条回答
  • 2020-12-10 13:28

    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/

    0 讨论(0)
  • 2020-12-10 13:36

    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>
    
    0 讨论(0)
  • 2020-12-10 13:37

    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

    0 讨论(0)
  • 2020-12-10 13:41

    It works fine on Chrome, but not on IE.

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

    0 讨论(0)
  • 2020-12-10 13:44

    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>
    
    0 讨论(0)
  • 2020-12-10 13:48

    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;
    }
    
    0 讨论(0)
提交回复
热议问题