简体   繁体   English

使用危险地设置组件反应组件,包含CSS

[英]React component with dangerouslySetInnerHTML, contain CSS

I have a React component that renders this element: 我有一个呈现此元素的React组件:

<div dangerouslySetInnerHTML={{__html: this.props.htmlString}}/>

It works fine, and the html is being rendered. 它工作正常,并且正在呈现html。 However, the issue that I'm having is that my client code has CSS in place, which is reaching into the component that I'm rendering from this.props.htmlString . 但是,我遇到的问题是,我的客户端代码中已有CSS,该CSS已从this.props.htmlString呈现到要渲染的组件中。 Is there a way to prevent my client CSS code from being applied to this component? 有没有一种方法可以防止将我的客户端CSS代码应用于此组件?

您必须以CSS中的元素为目标,并覆盖您不想应用的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM