【发布时间】:2018-11-10 22:56:57
【问题描述】:
我有一个 div,它是页面的宽度。我希望这个 div 中的一个很长的单词被打破和换行,所以所有内容都显示在屏幕上并且不会溢出/宽度永远不会大于 100%。
我尝试过overflow-wrap: break-word;,但这似乎不起作用。
谢谢。
.container { max-width: 100%;
margin: 0 20px;
display: table-cell;
text-align: center;
vertical-align: middle;
float: none; }
h1 { text-align: center;
font-weight: 800;
padding: 0px 20px;
color: #bec0ca;
font-size: 4.0rem;
line-height: 1.2;
letter-spacing: -.5rem;
font-weight: 800;
padding: 0px 40px;
max-width: 100%;
overflow-wrap: break-word;}
<div class="container">
<h1> this is the longestwordevergodhelpmewhycantthisjustwork longes word ever.</h1>
</div>
【问题讨论】:
-
您可能想看看this answer,因为它有两种不同的纯 CSS 解决方案。
-
您的容器的宽度从未设置过,因此不会破坏文字。