简体   繁体   English

防止危险的SetInnerHTML 在React 中继承css

[英]Prevent dangerouslySetInnerHTML from inheriting css in React

I don't want to mix my application with the css that is included in the html element that i'm receiving.我不想将我的应用程序与包含在我收到的 html 元素中的 css 混合在一起。

Is there a way to prevent dangerouslySetInnerHTML from inheriting style from the current page?有没有办法防止危险的SetInnerHTML 从当前页面继承样式?

 return (<div dangerouslySetInnerHTML={{ __html: template }}></div>)

You could display the content in an iframe, which would have its own CSS.您可以在具有自己的 CSS 的 iframe 中显示内容。

Not the solution you're asking for, but you could instead add a class to your div and override the styles that you don't want to impact your HTML content.不是您要求的解决方案,但您可以改为向 div 添加一个类并覆盖您不想影响 HTML 内容的样式。 This might be reasonable if you don't have many styles to override.如果您没有很多样式要覆盖,这可能是合理的。

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

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