让连续的英文数字字符换行显示
word-break: break-all;
让单行文字超出的时候使用点点点表示
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;(移动开发浏览器支持良好)
WebKit可以让多行文字点点点(利用Flexbox):
overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
淡出方式实现:
原理就是设定高度,然后最后那里用淡出做覆盖。例如line-height设为1.2em,然后需要三行文字,那么就把高度设为3.6em,然后把超出的overflow:hidden。在最后添加添加...或者用伪元素(before)半透明遮罩,因为不知道到底有几行字,所以方法就给最后一行整行添加半透明遮罩。
opera自己搞了一套:
.last-line {
height: 3.6em; /* exactly three lines */
text-overflow: -o-ellipsis-lastline;
}
在自适应的表格中,会撑大表格宽度,因为单元格的流动性,使得文字根本就不存在溢出这种说法,这个时候给table使用 table-layout: fixed 作用在于,让表格布局固定,也就是表格的宽度不是跟随单元格内容多少自动计算尺寸
使用表格相关display属性帮助构建web页面,总会遇到类似的连续英文字符不换行,或者单行文字溢出没有效果的。此时,可以用以下方法解决
display:table; width:100%; table-layout:fixed;
使用line-clamp截断多行文字,出现...
<p><a target="_top" href="http://codepen.io/romanrudenko/pen/ymHFh">Previous Step</a> 09.readmore</p> <div class="ellipsis"><div> <p>Call me Ishmael. Some years ago – never mind how long precisely – having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen, and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off – then, I account it high time to get to sea as soon as I can. <i></i></p> </div><a href="http://www.gutenberg.org/catalog/world/readfile?fk_files=2579906&pageno=11">Read More</a></div>
html, body, p { margin: 0; padding: 0; font-family: sans-serif;} .ellipsis { overflow: hidden; position: relative; height: 200px; line-height: 25px; margin: 20px; border: 5px solid #AAA; } .ellipsis:before { content:""; float: left; width: 5px; height: 200px; } .ellipsis > *:first-child { float: right; width: 100%; margin-left: -5px; } .ellipsis:after { content: "\02026 Read More"; box-sizing: content-box; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; float: right; position: relative; top: -25px; left: 100%; width: 7em; margin-left: -7em; padding-right: 5px; text-align: right; background-size: 100% 100%; /* 1706x1 image, gradient for IE9. Transparent at 0% -> white at 15% -> white at 100%.*/ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABqoAAAABCAMAAACRxg/eAAAABGdBTUEAALGPC/xhBQAAAwBQTFRFAAAAwDWRdwAAAP90Uk5Tfet1sDrNWZIeSRDcocCFLWj1CbhSfuMl1EGoYJkYM8Zui/rwBk15FefYKrxGtKydZQzfIdDJNj1VpFyVcY6BBBwxw2yI/Pfy7RInQ09ie5B0eIMDD+kb5eEk2tbSMMs5QL66tkyyrqpYpl+fm5drAf0H+AoN8+4TFhkf3SIoKwDONDfHO8Q+wURHSlBTVlqiXWNmaZNvcox2iYZ/fAL+9vsFCPkL9A4R8e/sFOjqFxrm5B3i4CDeIybb2SnX1SzT0S/PMsw1yjjIxTzCP79CvbtFuUi3tUuzTrGvUa1Uq6lXp6Vbo16gYZ6cZJpnmJZqlG2RcI9zjYp6d4eChIAu7+D8pQAAASFJREFUOMtjqK+fG2y/UKVwkVDxEsOSZSFcyz3LV6tXrJOtXB/msImjaqtxzfZI8R1etbu16vbx/zsY63hYrvGoWdPxeJaWU+ZtZxIkz3l3XNTpvMzZdS1F9YZP922RnrsWvQ8y2PoeW014miX93HfiK4NJbwQmv89z/qgw9bPNtK8BTDN+Bqr98JvDIDr7r93voD98s365zPyuOP2b7Rf/T+xTPli/y30r8zrnpf6L7Gc8/U8sH2U+lLqffk/vTtot5pup13WvJl8RvpR0Qft84lne9tNOrSflm0+YHos7wtpwyORAzH6JvdF7NHdF7eSu3ma0JWKz2MbwDRprQtcyrvIoW6m8wr10qeB8t6LFSgtcC+b9HwWjYBSMglEw2AEA3ckkQdBniOMAAAAASUVORK5CYII=); background: -webkit-gradient(linear, left top, right top, from(rgba(255, 255, 255, 0)), to(white), color-stop(15%, white)); background: -moz-linear-gradient(to right, rgba(255, 255, 255, 0), white 15%, white); background: -o-linear-gradient(to right, rgba(255, 255, 255, 0), white 15%, white); background: -ms-linear-gradient(to right, rgba(255, 255, 255, 0), white 15%, white); background: linear-gradient(to right, rgba(255, 255, 255, 0), white 15%, white); } .ellipsis a { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; text-indent: -9999px; } .ellipsis i, .ellipsis:after { font-style: normal; color: blue;} .ellipsis i:before { content: "Read More";}