Search code examples
cssreactjshtml-react-parser

How to set text-overflow ellpsis with dangerouslySetInnerHTML React?


I am trying to get the content saved as HTML tag and print it. I set it to 'text-overflow : ellpsis' because I need only brief details, but it doesn't work. Is there any workaround?

  const MyFeedList: IPost = MainData?.recentMyPostResponseList?.map((item: any) => {
    return (
      <div className="feed" key={item.id}>
        <img src={item.postImage} width="500px" />
        <h4>{item.postName}</h4>
        <h6
          style={{ overflow: "hidden", textOverflow: "ellipsis" }}
          dangerouslySetInnerHTML={{
            __html: DOMPurify.sanitize(item.content),
          }}
        ></h6>
      </div>
    );
  });

enter image description here


Solution

  • Try this:

    h6{           
        width:50%;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
    }