Html 如何在特定页面上禁用CSS?

Html 如何在特定页面上禁用CSS?,html,css,Html,Css,我在许多页面上使用了3个样式表(style1,style2,style3) style1用于我的网页标题 style2用于我的内容和 页脚的style3 现在,我想在我的主页上应用一个新的样式表,并仅对主页禁用style2 我为不同的元素添加了新的类,但在某些地方它仍然在检测我以前的样式表。如何禁用特定页面上的CSS?您必须使用jQuery禁用样式表,如: <script> $(function () { if (location.pathname.indexOf('/pag

我在许多页面上使用了3个样式表(
style1
style2
style3

  • style1
    用于我的网页标题
  • style2
    用于我的内容和
  • 页脚的
    style3
现在,我想在我的主页上应用一个新的
样式表
,并仅对主页禁用
style2


我为不同的元素添加了新的类,但在某些地方它仍然在检测我以前的
样式表。如何禁用特定页面上的CSS?

您必须使用
jQuery
禁用
样式表,如:

<script>
$(function () {
  if (location.pathname.indexOf('/pagename') >= 0) {
    $('link[href*="/media/css/csspagename.css"]').prop('disable', true);
  }
});
</script>

$(函数(){
if(location.pathname.indexOf('/pagename')>=0){
$('link[href*=“/media/css/csspagename.css”]”)prop('disable',true);
}
});

由于您没有包含代码来查看您是如何操作的,并且考虑到您将头作为包含文件:

使用PHP:

在主页中添加标题之前:

<?php $homepage = 1; ?>

//include your header//

//包括你的标题//
在引用CSS的标题中:

<link href="css/style1.css" rel="stylesheet" type="text/css" />

<link href="css/style3.css" rel="stylesheet" type="text/css" />

<link href="<?php if($homepage == 1){ echo "css/Home-style.css";}else{ echo "css/style2.css";}?>" rel="stylesheet" type="text/css" />


检查页面,然后抓取dom样式表数组对象并禁用任何需要的内容

if(window.location.href.indexOf("<name in page url >") > -1) {

//Next line will disable the 2nd stylsheet in the document . 

 document.styleSheets[1].disabled = true;

}

这将为您提供要删除的任何样式表的适当索引。

我们需要查看您遇到问题的代码。这是web,我只想禁用主页的core.css。从您的网站上看,它似乎是一个简单的
链接
元素。如果是这样,只需删除link元素并用新样式表替换即可。如果我删除link,所有其他页面都将受到干扰:(请参阅,我已经尝试将其粘贴到我的主页上,但没有取消我所需的工作表$(函数(){If(location.pathname.indexOf('/')>=0){$('link[href*=“./media/css/core.css”]')。prop('disable',true); } });
console.log(document.styleSheets)