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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?