停止自动换行分割单词

发布于 2024-09-25 05:15:55 字数 208 浏览 8 评论 0原文

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 技术交流群。

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

发布评论

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

评论(16

美胚控场 2024-10-02 05:15:55

使用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
alt text

瑾兮 2024-10-02 05:15:55

我遇到了同样的问题,我使用以下 css 解决了它:

.className {
  white-space:pre-wrap;
  word-break:break-word;
}

I had the same problem, I solved it using following css:

.className {
  white-space:pre-wrap;
  word-break:break-word;
}
你列表最软的妹 2024-10-02 05:15:55

请使用 nowrap 并且换行值不适合我。 nowrap 解决了这个问题。

white-space: nowrap;

Please use nowrap and wrap value didn't come for me. nowrap solved the issue.

white-space: nowrap;
谁许谁一生繁华 2024-10-02 05:15:55

可能有点晚了,但你可以添加这个 css 来阻止断词:

.element {
    -webkit-hyphens: none;
    -moz-hyphens:    none;
    -ms-hyphens:     none;
    hyphens:         none;
}

May be a bit late but you can add this css to stop word breaks:

.element {
    -webkit-hyphens: none;
    -moz-hyphens:    none;
    -ms-hyphens:     none;
    hyphens:         none;
}
碍人泪离人颜 2024-10-02 05:15:55

你可以试试这个...

body{
white-space: pre; /* CSS2 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP printers */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
word-wrap: break-word; /* IE */
}

{word-wrap:;} 是 IE 专有属性,而不是 css 的一部分。 firefox的处理是正确的。不幸的是,FF 不支持软连字符 / 。所以这不是一个选择。您可以分别插入头发或细空格 / (在数字实体上检查我)和 / 。

设置{overflow:hidden;}会切断溢出,而{overflow:auto;}会导致溢出启用滚动。

You can try this...

body{
white-space: pre; /* CSS2 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP printers */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
word-wrap: break-word; /* IE */
}

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

〗斷ホ乔殘χμё〖 2024-10-02 05:15:55

对我来说,父母比这个词更小。添加会在空格上中断,但不会在单词上中断:

    word-break: initial;

For me, the parent was smaller than the word. Adding will break on spaces, but not words :

    word-break: initial;
怀念你的温柔 2024-10-02 05:15:55

要阻止断词,您应该取消设置断词。默认值为正常,允许在断点处断字。

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 is normal, which allows word breaks but at break points.

overflow-wrap controls when word breaks happen.

You should instead set the overflow-wrap property to always 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:

  • If you want to disable all word breaks, even when it can't line break, i.e. japanese text, you can use the word-break: keep-all
  • *The value break-word may have been unsupported and is now deprecated, as is the word-wrap CSS property (initially added by MS for this same function).
时光礼记 2024-10-02 05:15:55

在我的情况下,我试图确保表格单元格内的单词在正确的断字处换行。

我发现我需要以下 CSS 来实现这一点。

table {
  table-layout:fixed;
}
td {
  white-space: wrap;
}

还要检查是否没有其他任何东西将 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.

table {
  table-layout:fixed;
}
td {
  white-space: wrap;
}

also check that nothing else is changing word-break to break-word instead of normal.

绝不放开 2024-10-02 05:15:55

使用 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

暮凉 2024-10-02 05:15:55

Firefox 浏览器上的断字问题。所以你可以使用来防止断词:

-webkit-hyphens: none;
-moz-hyphens: none;
hyphens: none;

Word break issue on Firefox browser. So you can use to prevent word-break:

-webkit-hyphens: none;
-moz-hyphens: none;
hyphens: none;
挽手叙旧 2024-10-02 05:15:55

我在我们的网站上使用此代码来阻止断词:

body {
    -ms-hyphens: none;
    -webkit-hyphens: none;
    hyphens: none;
}

I use this Code for our website to stop the word-breaking:

body {
    -ms-hyphens: none;
    -webkit-hyphens: none;
    hyphens: none;
}
開玄 2024-10-02 05:15:55
.className {
    hyphens: none;
    word-break: keep-all;
}
.className {
    hyphens: none;
    word-break: keep-all;
}
安穩 2024-10-02 05:15:55

对我有用的是将 overflow-wrap 设置为普通的:

overflow-wrap: normal;

What worked for me was setting overflow-wrap to normal:

overflow-wrap: normal;
缱倦旧时光 2024-10-02 05:15:55
    word-wrap: normal;

那对我来说是这样的。不再需要中途中断到下一行。

    word-wrap: normal;

That did it for me. No more mid-word breaking to the next line.

携余温的黄昏 2024-10-02 05:15:55

我在网格结构中遇到了类似的问题,我使用了,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.

烈酒灼喉 2024-10-02 05:15:55

这对我使用旧的 Webkit 有帮助 - 这个来自 phantomjs 2.1

.table td {
    overflow-wrap: break-spaces;
    word-break: normal;
}

This helped me with old Webkit - this one from phantomjs 2.1

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