CSS实现DIV超长截断,并显示._html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:23:54
Original
915 people have browsed it

DIV显示内容有时会超长,并把页面撑的很难看,

以前的做法是在JS中,或者后台判断其长度,过长就截断,

但由于中英文数字展示的宽度并不一样,截断的长度也就只能取最小值,

展示的效果也不好。利用CSS提供的方法,可以完美的解决该问题。

1 .project-Name{2     width:280px; 3     overflow:hidden; 4     text-overflow:ellipsis;5     white-space: nowrap;6 }
Copy after login

这里宽度是必须定义的,

overflow:hidden;表示超长部分不显示
Copy after login
text-overflow:ellipsis;表示超长显示...
Copy after login
white-space: nowrap;表示不折行显示<br /><br />该样式也可以应用于其他一些标签,最好在可以加TITLE的标签上使用,<br />因为可以加TITLE显示全部的信息哦
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template