停止自动换行分割单词
body { word-wrap: break-word;}
我一直在使用该代码(上面)将 body
中的文本放入其容器中。然而我不喜欢它的是它破坏了文字。
是否还有另一种方法,它不会分解单词,而只会在单词之后或之前换行?
编辑:这是在 UIWebView
中使用。
body { word-wrap: break-word;}
I've been using that code (above) to fit the text in the body
into it's container. However what I don't like about it, is that it breaks up words.
Is there another way where it will not break up words and only line break after or before a word?
EDIT: This is for use within a UIWebView
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
使用
white-space: nowrap;
。如果您在要设置的元素上设置了宽度,那么它应该可以工作。更新 -
在 Firefox 中渲染数据
use
white-space: nowrap;
. If you have set width on the element on which you are setting this it should work.update -
rendered data in Firefox
我遇到了同样的问题,我使用以下 css 解决了它:
I had the same problem, I solved it using following css:
请使用 nowrap 并且换行值不适合我。 nowrap 解决了这个问题。
Please use nowrap and wrap value didn't come for me. nowrap solved the issue.
可能有点晚了,但你可以添加这个 css 来阻止断词:
May be a bit late but you can add this css to stop word breaks:
你可以试试这个...
{word-wrap:;} 是 IE 专有属性,而不是 css 的一部分。 firefox的处理是正确的。不幸的是,FF 不支持软连字符 / 。所以这不是一个选择。您可以分别插入头发或细空格 / (在数字实体上检查我)和 / 。
设置{overflow:hidden;}会切断溢出,而{overflow:auto;}会导致溢出启用滚动。
You can try this...
{word-wrap:;} is an IE proprietary property, and not a part of css. firefox's handling is correct. Unfortunately, FF does not support a soft hyphen / . so that's not an option. You could possibly insert a hair or thin space, / (check me on the numeric entity) and / , respectively.
Making {overflow: hidden;} would cut the overflow off, and {overflow: auto;} would cause the overflow to enable scrolling.
对我来说,父母比这个词更小。添加会在空格上中断,但不会在单词上中断:
For me, the parent was smaller than the word. Adding will break on spaces, but not words :
要阻止断词,您应该取消设置
断词
。默认值为正常
,允许在断点处断字。overflow-wrap
控制何时发生断词。您应该将
overflow-wrap
属性设置为always
,以便仅当单词太长而无法在一行中容纳时(而不是溢出)才中断单词。默认的
normal
禁用断字,允许单词太长溢出元素的边缘。如果您的元素宽度是灵活的(例如 min-width 或 display:flex),并且您希望展开元素而不是换行,则可以使用值
break-word
。属性
word-break
确定单词是只在断点处中断,还是始终(当它们可能溢出时)。有关溢出换行的有用信息和演示 - MDN Web 文档
有关分词的信息
更多内容:
word-break: keep-all
break-word
可能不受支持,现已弃用,word-wrap
CSS 属性也是如此(最初由 MS 添加用于相同的功能) )。To stop words from breaking, you should unset
word-break
. The default isnormal
, which allows word breaks but at break points.overflow-wrap
controls when word breaks happen.You should instead set the
overflow-wrap
property toalways
to break words only when they are too long to fit on a line (instead of overflowing).The default
normal
to disable word breaks, allowing words too long to overflow the edge of the element.If your element width is flexible (e.g. min-width, or display:flex), and you want too expand the element instead of line breaking, you can use the value
break-word
.The property
word-break
determines whether words should only break at break points, or always (when they could overflow).Helpful info and demo on overflow-wrap - MDN Web Docs
Info on word-break
Further things:
word-break: keep-all
break-word
may have been unsupported and is now deprecated, as is theword-wrap
CSS property (initially added by MS for this same function).在我的情况下,我试图确保表格单元格内的单词在正确的断字处换行。
我发现我需要以下 CSS 来实现这一点。
还要检查是否没有其他任何东西将
word-break
更改为break-word
而不是normal
。In my situation I am trying to ensure words wrap at proper word-breaks within table cells.
I found I need the following CSS to achieve this.
also check that nothing else is changing
word-break
tobreak-word
instead ofnormal
.使用
white-space: nowrap;
CSS white-space 属性
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
了解有关空白示例的更多信息
Use
white-space: nowrap;
CSS white-space Property
white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
Know more about white-space example
Firefox 浏览器上的断字问题。所以你可以使用来防止断词:
Word break issue on Firefox browser. So you can use to prevent word-break:
我在我们的网站上使用此代码来阻止断词:
I use this Code for our website to stop the word-breaking:
对我有用的是将 overflow-wrap 设置为普通的:
What worked for me was setting overflow-wrap to normal:
那对我来说是这样的。不再需要中途中断到下一行。
That did it for me. No more mid-word breaking to the next line.
我在网格结构中遇到了类似的问题,我使用了,word-break:break-word;
在我的网格中,我的问题得到了解决。
I faced a similar problem in my grid structure and I used, word-break: break-word;
in my grid and my issue got resolved.
这对我使用旧的 Webkit 有帮助 - 这个来自 phantomjs 2.1
This helped me with old Webkit - this one from phantomjs 2.1