如何使用 dangerouslySetInnerHTML React 设置文本溢出省略号?
How to set text-overflow ellpsis with dangerouslySetInnerHTML React?
我正在尝试将内容保存为 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>
);
});
试试这个:
h6{
width:50%;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
我正在尝试将内容保存为 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>
);
});
试试这个:
h6{
width:50%;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}