Tailwind: text-overflow: ellipsis?

19,458

Solution 1

CSS property text-overflow: ellipsis; cannot be used alone.

Along with text-overflow, you should use other properties like:

overflow: hidden; 
white-space: nowrap; 

You can use .truncate class to achieve this. Here is the link from the Tailwind documentation.

Solution of the initial problem:

&__title {
    @apply truncate;
}

Solution 2

Use class truncate

<div class="overflow-hidden truncate w-2">Long long long text</div>

See https://tailwindcss.com/docs/word-break/#app

overflow-hidden will hide overlaps, truncate adds ellipsis and optional w-2 set width

Share:
19,458

Related videos on Youtube

Ced
Author by

Ced

Junior full-stack developer, Specialised in Front-End

Updated on June 04, 2022

Comments

  • Ced
    Ced almost 2 years

    Is there a way to use

    text-overflow: ellipsis
    

    Thought the Tailwind CSS Framework

    I would like to use the tailwind convention like :

    &__title {
        @apply text-overflow-ellipsis;
    }
    

    Instead of

    &__title {
        text-overflow: ellipsis;
    }
    
    • AKNair
      AKNair over 5 years
      text-overflow: ellipsis; cannot be used alone, Along with text-overflow, you should other properties like overflow: hidden; white-space: nowrap; also. You can use .truncate class to achieve this. Here is the link from the documentation: tailwindcss.com/docs/whitespace-and-wrapping