HTML 文本区域水平滚动

发布于 2024-07-10 15:59:52 字数 125 浏览 5 评论 0原文

我想为 HTML 页面中的文本区域提供水平滚动。 如果我输入没有换行符的长行,则滚动条应该显示而不换行。 一些朋友建议使用overflow-y CSS属性,这对我不起作用。 我使用的浏览器是 IE 6+ 和 Mozilla 3+。

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+.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

病毒体 2024-07-17 15:59:52

我想出了一种不符合 W3c 标准的方式,它可以在 IE 和 Firefox 中工作,顺便在 Chrome 中也可以工作。

我添加了属性 wrap ,其值为 off,即

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.

·深蓝 2024-07-17 15:59:52

要设置不换行,您可以使用:

white-space: nowrap;

对于其他值: https: //developer.mozilla.org/en-US/docs/Web/CSS/white-space

注意:然而,贬值的 wrap="off" 似乎是遗留的唯一方法浏览器支持。 尽管它不兼容 HTML 5,但如果您的目标是所有浏览器,它仍然是我的首选。

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.

逆蝶 2024-07-17 15:59:52

如果您有包含 LF 的预格式化文本,则应将 white-space: pre; 添加到 css。 这将保留文本中已有的新行,并且不会换行长行。

这适用于所有版本的 Firefox、所有基于 Webkit 的浏览器以及 IE6+。

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

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

终陌 2024-07-17 15:59:52

试试这些:

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

还应该有一个 -moz-scrollbars-horizo​​ntal

Try these:

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

there should also be a -moz-scrollbars-horizontal

怂人 2024-07-17 15:59:52

使用 white-space: pre; 作为 CSS 属性。

https://developer.mozilla.org/en-US/文档/Web/CSS/空白

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文