How to restrict character limit by line or # of characters with css?

╄→гoц情女王★ 提交于 2019-12-03 03:13:00

You can try text-overflow, however it has some restrictions, but still might suite you:

Example

<div id="container">
    This is some short content to demonstrate the css-property
    text-overflow
</div>​

#container{
    width:100px;
    height:50px;
    border:1px solid red;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space: nowrap;   
}​

Not characters, but you can set a width of an element in pixels and use text-overflow property which should add "...".

Also, you can limit number of lines by setting height of an element to, for instance, 30px and setting line-height CSS property to 15px and add overflow:hidden. That way you will have exact two lines of text.

.twoLines{
   height:30px;
   line-height:15px;
   overflow:hidden;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!