Home > Software design >  How to truncating text in TailwindCSS?
How to truncating text in TailwindCSS?

Time:02-13

I am using truncate in TailwindCSS to make text ellipsis if text overflow more one line but it not works. How can i fixed it?

My code not works below:

  <div className="ml-1 inline-block">
     <span>Label: </span>
     <span className="font-semibold truncate">
       long texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
     </span>
  </div>

CodePudding user response:

First thing first your parent or the element must have a specific width otherwise how the element suppose to know when to stop and truncate? also in order to truncate to work your element's display must not be display inline since span is display inline by default you should change it to block

  <div className="ml-1 inline-block w-[200px]">
     <span>Label: </span>
     <span className="font-semibold truncate block">
       long texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
     </span>
  </div>
  • Related