这个问题在这里已有答案:
-
How to force a line break in a loooooong word in a DIV? 13个答案
-
What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS 9个答案
我有一个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>
6 回答
根据Mozilla开发人员的参考:
使用overflow-wrap并将属性的值设置为“break-word”
你正在寻找关键词属性 .
另外,如果你想控制html中单词的中断位置,请查找
<wbr>
标记 .你可以添加
word-break: break-all;
,但它会将内容推到左边?这应该达到你正在寻找的效果:)
Credit https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/
JSFiddle
.css
.html
如果要通过浏览器执行此操作,则必须将连字符添加到自动 .
如果你想手动完成它
看我的更新: