【问题标题】:How to set text-overflow ellpsis with dangerouslySetInnerHTML React?如何使用 dangerouslySetInnerHTML React 设置文本溢出省略号?
【发布时间】:2021-09-10 19:13:14
【问题描述】:

我正在尝试将内容保存为 HTML 标记并打印出来。 我将它设置为'text-overflow : ellpsis',因为我只需要简短的细节,但它不起作用。 有什么解决办法吗?

  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>
    );
  });

【问题讨论】:

  • 请显示呈现的 HTML。这可能是因为你在那里的巨大形象; text-overflow 只影响文本,不影响图像。

标签: css reactjs html-react-parser


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 2021-05-26
    • 2020-12-10
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2017-01-21
    • 2019-04-29
    • 2019-03-06
    相关资源
    最近更新 更多