水平滚动

我想提供一个水平滚动到我的 HTML 页面的文本区。如果我键入一个没有换行符的长行,那么滚动应该不包装地出现。一些朋友建议使用 overflow-y CSS 属性,这对我来说不起作用。我使用的浏览器是 IE6 + 和 Mozilla 3 + 。

99081 次浏览

Try these:

overflow: scroll;
overflow-y: scroll;
overflow-x: scroll;
overflow:-moz-scrollbars-vertical;

there should also be a -moz-scrollbars-horizontal

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.

I added the attribute wrap with value off, that is <textarea cols=80 rows=12 wrap='off'> is what I have done.

To set no wrapping, you would use:

white-space: nowrap;

For other values: 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.

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.

This works in all versions of Firefox, all Webkit-based browsers, and IE6+.

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space