这是 Chris Coyier 的一支笔,在他的文章处理长词和 URL中提到:https ://codepen.io/team/css-tricks/pen/RWaNxr 。
<style>
.hyphenate {
/* Careful, this breaks the word wherever it is without a hyphen */
overflow-wrap: break-word;
word-wrap: break-word;
/* Adds a hyphen where the word breaks */
-webkit-hyphens: auto;
-ms-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}
/* Demo Styles */
body {
background: #333;
font-family: 'Open Sans', sans-serif;
}
.container {
background: #fff;
border-radius: 5px;
width: 300px;
margin: auto auto 25px;
padding: 25px;
}
</style>
<div class="container">
<p class="hyphenate">For more information, please visit: http://csstricks.com/thisisanonexistentandreallylongurltoaddtoanytextinfactwhyareyoustillreadingit.</p>
</div>
<div class="container">
<p class="hyphenate">According to Wikipedia, The longest word in any of the major English language dictionary is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis.</p>
</div>
如果您只是在浏览器中打开此链接,它在 Firefox 中的外观如下:
如果将所有内容复制到本地 HTML 文件中,它的外观如下:
为什么看起来不一样?