从 div 溢出

发布于 2024-11-07 10:43:11 字数 440 浏览 0 评论 0原文

我有一个 div,客户端将执行一些操作(使用 JavaScript)来更改内容。有时,此内容会变得非常长。有没有一种“简单”的方法来做到这一点?我搞乱了CSS“溢出”属性,它工作正常,但我宁愿只有一个垂直滚动条,没有水平滚动条。

这也是假设某些内容不包含空格(这将产生正常效果)。

如果需要的话,我需要它把它拆分在单词的中间。

示例:

I want the overflow to acti
vate even if it is in the m
iddle of a word.

如果可以的话,谢谢。这是我正在使用的jsFiddle:

http://jsfiddle .net/DalexL/znzk2/

I have a div that the client will be doing some actions that (with JavaScript) will change the content. Sometimes this content will get annoyingly long. Is there a "simple" way to do this? I've messed with the CSS "Overflow" property and it works alright but I'd rather only have a vertical scroll bar, no horizontal scroll bars.

This is also assuming that some of the content doesn't include spaces (which will produce the normal effect).

I need it to split it in the middle of the word if it requires doing so.

Example:

I want the overflow to acti
vate even if it is in the m
iddle of a word.

Thanks if you can. Here is a jsFiddle of what I'm kind of working with:

http://jsfiddle.net/DalexL/znzk2/

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

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

发布评论

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

评论(4

執念 2024-11-14 10:43:11
overflow-y: auto
overflow-x: none

还有

word-wrap: break-word;
overflow-y: auto
overflow-x: none

and also

word-wrap: break-word;
苦笑流年记忆 2024-11-14 10:43:11

还有 word-break

word-break: break-all;

当前支持有限,似乎是 IE9、Chrome ,仅限 Safari,但对于 hyphenate 选项可能值得

word-break: hyphenate;

there's also word-break

word-break: break-all;

current support is limited though, appears to be IE9, Chrome, Safari only, but may be worthwhile for the hyphenate option

word-break: hyphenate;
那支青花 2024-11-14 10:43:11

你试过设置div的宽度吗?及其溢出到 overflow:auto
我认为这应该有效。

have you tried setting the width of the div? and its overflow to overflow:auto
I think that should work.

怀念你的温柔 2024-11-14 10:43:11

如果您将 html 和 body 溢出设置为隐藏,并且将 div 高度设置为 100%(使用自动溢出),则不会起作用。 div 将继续流出窗口,因为它被告知使用 100% 的 body 高度。如果你想让溢出起作用,它需要在某个点有一个不超过主体高度的最大高度,这样就不会隐藏任何东西。 http://jsfiddle.net/robx/XvcXC/1

编辑:所以我将你的问题理解为自从我第一次看到你的问题以来,似乎有些事情发生了变化。此处更新 http://jsfiddle.net/robx/XvcXC/2/ 以打破长行的文本。

If you set html and body overflow to hidden, and your div height to 100% with overflow auto, that will not work. The div will keep flowing out of the window as it was told to use 100% height of the body. if you want overflow to work, it needs to have a max-height at some point not exceeding the body height so that nothing gets hidden. http://jsfiddle.net/robx/XvcXC/1

Edit: So i misunderstood your problem as seem like something has changed since i first saw your question. Updated here http://jsfiddle.net/robx/XvcXC/2/ to break long lines of text.

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