从 div 溢出
我有一个 div,客户端将执行一些操作(使用 JavaScript)来更改内容。有时,此内容会变得非常长。有没有一种“简单”的方法来做到这一点?我搞乱了CSS“溢出”属性,它工作正常,但我宁愿只有一个垂直滚动条,没有水平滚动条。
这也是假设某些内容不包含空格(这将产生正常效果)。
如果需要的话,我需要它把它拆分在单词的中间。
示例:
I want the overflow to acti
vate even if it is in the m
iddle of a word.
如果可以的话,谢谢。这是我正在使用的jsFiddle:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
还有
and also
还有 word-break
当前支持有限,似乎是 IE9、Chrome ,仅限 Safari,但对于
hyphenate
选项可能值得there's also word-break
current support is limited though, appears to be IE9, Chrome, Safari only, but may be worthwhile for the
hyphenate
option你试过设置div的宽度吗?及其溢出到
overflow:auto
我认为这应该有效。
have you tried setting the width of the div? and its overflow to
overflow:auto
I think that should work.
如果您将 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.