[CSS] Truncate long text to a number of lines

p.intro {
    width: 300px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3; /* Truncate when no. of lines exceed 3 */
    overflow: hidden;
}

Truncate overflowing text:

p.intro {
    width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
  • Explicit width, so bounds for clipping will ever be reached.
  • Browser wraps below long text that do not fit within an element's width. So you need to prevent that: white-space: nowrap;.
  • Content that overflows should be clipped: overflow: hidden;.
  • Pad a string with an ellipsis(...) when text is about to be clipped: text-overflow: ellipsis;.

 

Read more: https://dev.to/smitterhane/13-css-tricks-that-will-give-you-an-adrenaline-rush-5908

posted @   Zhentiw  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-07-20 [SAA + SAP] 06. Containers on AWS: ECS, Fargate, ECR & EKS
2020-07-20 [XState] Assignement actions
2020-07-20 [XState] Using global actions prop for testing
2018-07-20 [Vue @Component] Simplify Vue Components with vue-class-component
2017-07-20 [HTML] Change an HTML5 input's placeholder color with CSS
2017-07-20 [Node] Run Any Version of a Node Tool with npx
2016-07-20 [CSS] Make element not selectable
点击右上角即可分享
微信分享提示