How can I get my text to be two lines with padding and ellipsis?

Issue

I’m having issues getting my text to be on two lines with ellipsis. I am able to get my ellipsis working but modifying line-height and height do nothing to change how many lines of text are shown. Any help on why I’m unable to change the number of lines would be great.

https://codepen.io/Joe_Scotto/pen/gjXoJy

Solution

Try this out

CSS

.slick-slide {
  border-radius: 7px;
  height: 200px;
  margin: 0 10px;
  overflow: hidden;
  position: relative;
  width: 200px;

  img {
    bottom: 0;        
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
  }

  .info {
    background: rgba(black, 0.5);
    border: 1.5px solid white;
    border-radius: 7px;
    bottom: 10px;
    color: white;
    left: 0;
    margin: 0 10px;
    padding: 7px 10px;
    position: absolute;
    text-align: center;
    right: 0;
    z-index: 1;

    h6 {
      display: -webkit-box;
      margin: 0 auto;
      overflow: hidden;
      text-align: center;
      text-overflow: ellipsis;            
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;            
    }
  }
}

DEMO

All you need to do is adjust the -webkit-line-clamp value to however many lines you want visible.

Answered By – dysfunc

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.