Wrap a text within only two lines inside div

前端 未结 11 749

I want to wrap a text within only two lines inside div of specific width. If text goes beyond the length of two lines then I want to show elipses. Is there a way to do that

11条回答
  •  粉色の甜心
    2020-12-04 09:35

    I believe the CSS-only solution text-overflow: ellipsis applies to one line only, so you won't be able to go this route:

    .yourdiv {
    
        line-height: 1.5em; /* Sets line height to 1.5 times text size */
        height: 3em; /* Sets the div height to 2x line-height (3 times text size) */
        width: 100%; /* Use whatever width you want */
        white-space: normal; /* Wrap lines of text */
        overflow: hidden; /* Hide text that goes beyond the boundaries of the div */
        text-overflow: ellipsis; /* Ellipses (cross-browser) */
        -o-text-overflow: ellipsis; /* Ellipses (cross-browser) */
    }
    

    Have you tried http://tpgblog.com/threedots/ for jQuery?

提交回复
热议问题