删除所有 CSS 规则
有没有办法在样式表加载后清除所有 CSS 规则?
我必须使用专有的 JavaScript 库(ESRI 的 ArcGIS Server API) 是建立在 Dojo 之上的。我广泛使用 Dojo 的小部件,并希望使用 Dojo 的 claro 主题,但不幸的是,ESRI 库通过加载异地 CSS 文件(可能还有在 JS 中硬编码的 CSS 规则)来修改 CSS。这最终会破坏 Claro 主题。
如此多的 Dojo 小部件 CSS 类被重写并创建了新规则,只需清除所有 CSS 并重新加载标准 Dojo 样式表似乎更容易/更安全。
像下面这样的东西会很好:
* {none}
但我想我最终必须使用 Dojo 或 jQuery 来完成这个任务。
Is there a way to wipe out all CSS rules once style sheets have already been loaded?
I have to use a proprietary JavaScript library (ESRI's ArcGIS Server API) which is built on top of Dojo. I make extensive use of Dojo's widgets and would like to use Dojo's claro theme but unfortunately the ESRI library mungs up the CSS by loading in off-site CSS files (and probably CSS rules hard-coded in the JS). This ends up mangling the Claro theme.
So many Dojo widget CSS classes get rewritten and new rules get created that just wiping out all CSS and reloading the standard Dojo stylesheets seems easier/safer.
Something like the following would be nice:
* {none}
but I figure I'll have to end up using either Dojo or jQuery to accomplish this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 Paul Irish 编写的名为 RefreshCSS 的小书签:
它刷新页面上的 CSS 样式表,而不刷新页面本身。
我想你可以对它做一些改变并让它做你想要的事情?
另一种可能有效的使用 jQuery 的方法是在页面加载后运行它:
$('head link, head style').remove();
check out this bookmarklet called RefreshCSS by Paul Irish:
It refreshes the CSS stylesheets on a page, without refreshing the page itself.
I think you could do some alterations to it and get it to do what you want?
Another approach using jQuery that might work is to run this once the page has loaded:
$('head link, head style').remove();
没有。可悲的是,这样的事情并不存在。
这些相关问题的答案几乎概括了解决方法的可能性。
有没有办法在不使用 iframe 的情况下将 html 块“沙箱”到远离其页面 CSS 的地方?
重置 CSS页面的某些区域?
防止 meyer 重置 css 扰乱动态内容
如何重置html文档中间的css?
Nope. Sadly, such a thing does not exist.
The answers to these related questions give pretty much the rundown on what is possible in terms of workarounds.
Is there a way to “sandbox” an html block away from its page's CSS without using iframes?
Reset CSS for a certain area of the page?
prevent meyer reset css to mess with dynamic content
How to reset css in middle of html document ?
总是有
document.head.innerHTML = "";
但它确实会清理空间,所以你必须存储任何脚本、元标签、标题或任何你想保存的内容再次添加它们。There is always
document.head.innerHTML = "";
But it really cleans house so you have to store away any scripts,metatags, titles or whatever you want to save and add them again.