[英]Is there a way to load an external stylesheet only for a specific part of the page (i.e. the header) and "unload" that stylesheet for all other parts?
I am trying to integrate a help center (from Zendesk) seamlessly.我正在尝试无缝集成帮助中心(来自 Zendesk)。 For that I have copied the Header and the Footer of our mainpage into the help center page.为此,我已将主页的 Header 和页脚复制到帮助中心页面。 I apply the CSS of the external page in the header with this:我将外部页面的 CSS 应用到 header 中:
<link href=".../web/cache/Test.css" media="all" rel="stylesheet" type="text/css" />
The problem is that using that it will apply the stylesheet to the entire page and mess up all the other articles and content.问题是使用它会将样式表应用到整个页面并弄乱所有其他文章和内容。
I need a way to apply the stylesheet only to a specific part of the page(the header).我需要一种方法将样式表仅应用于页面的特定部分(标题)。 Another note is that the stylesheet is huge, and I cannot edit it in any way(eg editing the selectors to only apply to the header class)另一个注意事项是样式表很大,我无法以任何方式对其进行编辑(例如,将选择器编辑为仅适用于 header 类)
I tried searching for solutions but only came up with 8 year old posts about using something like <style scoped>
, though that also seemed outdated.我尝试寻找解决方案,但只找到了 8 年前关于使用<style scoped>
类的帖子,尽管这似乎也已过时。
I also tried using this javascript function I found, to no avail:我也尝试使用我发现的这个 javascript function,但无济于事:
function applyCSSFileToElement(cssUrl, elementSelector, callbackSuccess, callbackError) {
callbackSuccess = callbackSuccess || function(){};
callbackError = callbackError || function(){};
$.ajax({
url: cssUrl,
dataType: "text/css",
success: function(data) {
applyCSSToElement(data, elementSelector);
callbackSuccess();
},
error: function(jqXHR) {
callbackError();
}
})
}
How about this?这个怎么样?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.