HTML 文本区域水平滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/424192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML Textarea horizontal scroll
提问by Shyam
I would like to provide a horizontal scroll to a textarea in my HTML page. The scroll should appear without wrapping, if I type a long line without a line break. A few friends suggested using overflow-y CSS attribute, which did not work for me. The browsers that I use are IE 6+ and Mozilla 3+.
我想为我的 HTML 页面中的文本区域提供水平滚动。如果我输入一个没有换行符的长行,滚动应该不换行。一些朋友建议使用overflow-y CSS 属性,这对我不起作用。我使用的浏览器是 IE 6+ 和 Mozilla 3+。
采纳答案by Aram Kocharyan
To set no wrapping, you would use:
要设置不换行,您可以使用:
white-space: nowrap;
For other values: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
对于其他值:https: //developer.mozilla.org/en-US/docs/Web/CSS/white-space
NOTE: However the depreciated wrap="off"
seems to be the only way for legacy browser support. Though it isn't HTML 5 compliant, it's still my preference if you're targeting all browsers.
注意:然而,折旧wrap="off"
似乎是支持旧版浏览器的唯一方法。尽管它不符合 HTML 5,但如果您针对所有浏览器,它仍然是我的首选。
回答by Shyam
I figured out to do it in a non-W3c-compliant way and it is working in both IE and Firefox and incidentally in Chrome too.
我想以一种不符合 W3c 的方式来做它,它在 IE 和 Firefox 中都可以使用,顺便说一下,在 Chrome 中也是如此。
I added the attribute wrap
with value off
, that is <textarea cols=80 rows=12 wrap='off'>
is what I have done.
我添加了wrap
value属性off
,这就是<textarea cols=80 rows=12 wrap='off'>
我所做的。
回答by Azdle
If you have pre-formatted text that includes LFs, you should add white-space: pre;
to the css. That will preserve the new lines that are already in the text and will not wrap long lines.
如果您有包含 LF 的预格式化文本,则应添加white-space: pre;
到 css。这将保留文本中已经存在的新行,并且不会换行长行。
This works in all versions of Firefox, all Webkit-based browsers, and IE6+.
这适用于所有版本的 Firefox、所有基于 Webkit 的浏览器和 IE6+。
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
来源:https: //developer.mozilla.org/en-US/docs/Web/CSS/white-space
回答by Filip Ekberg
Try these:
试试这些:
overflow: scroll;
overflow-y: scroll;
overflow-x: scroll;
overflow:-moz-scrollbars-vertical;
there should also be a -moz-scrollbars-horizontal
还应该有一个 -moz-scrollbars-horizontal