dqtiober37522 2015-10-14 06:52
浏览 58
已采纳

Php - 根据容器大小减少文本长度

I have a wordpress based website with plots of movies and stuff, and I'd just like to make excerpts of the plots so that they look like "Word word word word..." with the dots in the end if the plot doesn't fit the container. So I guess there isn't a way in php to know if the text will fit or not in the container, but what can I do to make some kind of excerpt like the one I described? If the only solution is just choosing a number of chars and set that as a limit, how do I find this number? Thanks in advance

  • 写回答

3条回答 默认 最新

  • dongqiangse6623 2015-10-14 07:01
    关注

    in css you have a property for text-overflow: eclipse

    So you can use that for this.

    <style>
    #div1 {
        white-space: nowrap; 
        width: 12em; 
        overflow: hidden;
        text-overflow: clip; 
        border: 1px solid #000000;
    }
    
    #div2 {
        white-space: nowrap; 
        width: 12em; 
        overflow: hidden;
        text-overflow: ellipsis; 
        border: 1px solid #000000;
    }
    </style>
    
    
    <p>This div uses "text-overflow:clip":</p>
    <div id="div1">This is some long text that will not fit in the box</div>
    
    <p>This div uses "text-overflow:ellipsis":</p>
    <div id="div2">This is some long text that will not fit in the box</div>
    

    you can see the difference between both. see demo here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度