属性:强制换行:word-wrap:break-word; word-break:break-all; white-space:pre-wrap;
强制不换行:overflow:hidden; width:300px; white-space:nowrap; text-overflow: ellipsis;
http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
换行的 table: |
|
---|---|
http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |
未换行的 table: |
|
---|---|
http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | http://google.com/abcdefghijklmnopqrstuvwxyz 000_^_^_000_(^o^)_000 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |
/* @ 名称: 强制换行 @ 用法: * 一般块级元素用:.as-wrap * table标签中需添加:.as-wrap-table @ 例子: <p class="as-wrap">…</p> <table class="as-wrap as-wrap-table"></table> */ /* 一般 block-level 元素 */ .as-wrap, .as-wrap td, .as-wrap th{ word-wrap:break-word;word-break:break-all; } /* table */ .as-wrap-table{ table-layout:fixed; }
解决方案描述
单行文本,如果这里字太多了就会显示省略号省略号啊!
如果父层有宽度,这里不设置宽度,IE6不行,其他浏览器都OK
.ellipsis{ width: 300px; /*设置宽度*/ white-space: nowrap; /*设置不折行*/ overflow: hidden; /*设置超过的隐藏*/ text-overflow: ellipsis; /*这就是省略号喽*/ } /* 测试 */ .box{width:300px;} .box p{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } 如果仅依赖父层的宽度自适应,内层不设置宽度,仅IE6不支持,其他浏览器都OK,内层设置width:100%;可以解决此问题。
如上代码设置,都是必选项,每个属性都不可缺少,且仅适用于单行文本。
实践出真知