简体   繁体   English

在HTML / XHTML TextArea中对齐文本

[英]Justify Text in a HTML/XHTML TextArea

I am currently trying to justify text in a textarea, unfortunately the CSS: 我目前正在尝试在textarea中证明文本,不幸的是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. 我在Firefox 3和IE 7都尝试过这个,没有运气。

Is there any way around this? 有没有办法解决?

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>

Depending on your target browser... this solution works in Chrome. 取决于您的目标浏览器...此解决方案适用于Chrome。 It does not work work in Firefox however... but I'll post it anyway. 但它在Firefox中无法正常工作......但无论如何我都会发布它。

In addition to setting text-align: justify, you must also set white-space: normal. 除了设置text-align:justify之外,还必须设置white-space:normal。

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

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

For me (in Firefox), this code works perfectly: 对我来说(在Firefox中),这段代码非常有效:

textarea{
    resize: none;
    text-align: justify;
    white-space: pre-line;
    -moz-text-align-last: left;
    text-align-last: left;
}

I believe that common practice is to use the TEXTAREA for input without worying about justification; 我认为,通常的做法是使用TEXTAREA进行输入而不需要理由; and then, once the input is processed (ie the FORM is submitted, or an event of the TEXTAREA is captured), the contents are displayed in a non-editable text element (such as P , SPAN , TD ) where the text-align: justify; 然后,一旦处理了输入(即提交了FORM ,或者捕获了TEXTAREA的事件),内容就会显示在text-align: justify;的不可编辑的文本元素(如PSPANTD )中text-align: justify; style attribute will be honored. style属性将被尊重。

Using a common div with contenteditable="true" worked in my case. 在我的案例中使用具有contenteditable =“true”的公共div Doesn't work for most mobile browsers though. 但是对大多数移动浏览器不起作用。

<div contenteditable="true">Some content</div>

It works fine on Chrome, but not on IE. 它适用于Chrome,但不适用于IE。

text-align: justify; text-align:justify; white-space: normal; 白色空间:正常;

i dont think this is possible in the html textarea element. 我认为这不可能在html textarea元素中。 you might be able to use some sort of wysiwyg editor (editable div). 你也许可以使用某种所见即所得的编辑器(可编辑的div)。 ie. 即。 fckeditor FCKeditor的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对齐和居中<textarea>&lt;i&gt;text HTML/CSS?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;文本 HTML/CSS?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我有一个 textarea,我希望它是合理的,所以所有行的宽度都相等,并且当它不是最大行长时,以文本为中心位于 textarea 的中间。</p><p> 这是我的文本区域:</p><pre> &lt;textarea class="Whiteboard" type="text" placeholder="Type something..."&gt;&lt;/textarea&gt;</pre><p> ...和 ​​CSS:</p><pre> textarea.Whiteboard{ resize: none; background-color: #F1F1F1; border: none; height: 500px; width: 800px; text-align: center; font-size: 50px; }</pre><p> 谢谢你们</p></div> - Justify and Center <textarea> text HTML/CSS? 使用HTML对齐和对齐文本 - Align and Justify Text with HTML 证明段落文本HTML - Justify Paragraph Text HTML 调整html中的包装文字 - Justify wrapped text in html text-justify:newspaper html的替代 - alternative of text-justify:newspaper html 有什么方法可以垂直对齐HTML中的文本? - Is there any way to vertically justify text in HTML? 对齐 Rmarkdown html output 中的文本 YAML Z099FB995346F31C749F6E40DB0F395E - Justify text in Rmarkdown html output in YAML header 如何在 html 表格行中对齐文本 - How to justify text in html table row Winnovative HTML到PDF转换器将文本对齐 - Winnovative HTML to PDF converter Justify text 如何证明HTML / CSS中的文本正确? - How can I justify text in HTML/CSS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM