html - 单词在换行符上中断并溢出

标签 html css

一种风格

#test {
    overflow-x: auto;
    white-space: pre-wrap; /* css-3 */
    white-space: -moz-pre-wrap !important;
    white-space: -pre-wrap;
    white-space: -o-pre-wrap;
    width: 99%;
    word-wrap: break-word;
}
#wrap {
    margin: 0 auto; width: 50%;
}

div id="test"中的单词如下:

no  //this is end of first line
thing //this is beginning of the next line

<div id="wrap">
    <div id="test"></div>
</div>

原词是nothing

如何解决?

最佳答案

仅使用 white-space: nowrap; 来获得完整的单词而不中断。但我确信 nothing 之间的空白不能被删除,除非你从文本中删除并将其写为 nothing

#test {
    overflow-x: auto;
    white-space: nowrap;
    width: 99%;
    word-wrap: normal;
}
#wrap {
    margin: 0 auto; width: 50%;
}
<div id="wrap">
    <div id="test">
  no 
thing
  </div>
</div>

关于html - 单词在换行符上中断并溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40983745/

相关文章:

javascript - 在 Firefox 中单击鼠标时无法选择所有输入元素文本

html - www.flipboard.com 上的响应式 + 滚动效果

html - VSCode:CSS中的自动完成功能是在您的HTML标记中首先创建的类。为此扩展吗?

javascript - 文档选择中的索引错误,而所选文本有一个点

html - 如何在子 div 上创建等间距的 div 容器

html - 无法让 Twitter Bootstrap 崩溃工作

html - 在 Angular2 中对齐 ngForm 内容

javascript - bootstrap 4 无法让偏移量 col 工作

javascript - 使用 PHP 更改 CSS 值

css - div的自动高度