Home > Software design >  Line-clamp works unexpectedly
Line-clamp works unexpectedly

Time:10-14

I am trying to make line-clamp work. I use Tailwind CSS (unfortunately). As I did many times before I added utility class line-clamp-2 (I need to show only 2 lines of the text). As you can see ellipsis appeared but on the third line we see the other part of the text. Could someone help me, please? There is the mark up of that dropdown. Screenshot is attached either.

  <ul >
    <li
      
    >
      {{ currentUserAlias }}
    </li>
    <li v-for="(profileMenuItem, index) in items" :key="index" >
      <Component
        :is="'a'"
        
        :to="profileMenuItem.href"
        :href="getAbsoluteLink(profileMenuItem.href)"
      >
        {{ profileMenuItem.title }}
      </Component>
    </li>
  </ul>

CodePudding user response:

Part of the text on the next line showed because of py-2 (padding will change element height). line-clamp-{n} utility adds dots at the end of n line but it does NOT magically removes text from the DOM (you may inspect it in a browser) - that is why it also adds overflow: hidden; property

In order to fix it, add inner wrapper for your text and put line-clamp-2 on it

<ul >
    <li
      
    >
      <div >
        {{ currentUserAlias }}
      </div>
    </li>
    
    // that part is irrelevant
  </ul>

Now no matter what outer padding is you will have two clamped lines

  • Related