【问题标题】:How to limit the number of lines for a text with HTML/CSS?如何使用 HTML/CSS 限制文本的行数?
【发布时间】:2013-12-14 12:55:29
【问题描述】:

我有一个文本,我想在相应的宽度内只显示 3 或 4 行。我使用它,但它只将文本限制为 1 行:

 text-overflow: ellipsis; 
 max-width: XXXpx;
 white-space: nowrap; 
 overflow:hidden;

我怎样才能做到这一点?

【问题讨论】:

  • 试试height: 5em;,因为1em是一个字母的高度(m),然后是line-height:1.25em;,所以显示了4行。不确定它是否会起作用,只是一个想法。
  • max-height 和 line-height 应该可以工作。幻数是 max-height = line-height * no of lines
  • @Francisco 感谢您的建议,但不,它不起作用。
  • @KrishnaDhungana,谢谢你,我听从了你的建议,它奏效了。

标签: html text limit


【解决方案1】:

在样式中添加高度属性。

 style="height:11em;"

【讨论】:

    猜你喜欢
    • 2022-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    相关资源
    最近更新 更多