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
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报