2016-06-20 40 views
-3

可以请别人帮我吗?我的网页是:http://etinklapis.lt/在javascript addclass之后,它添加了类但css属性不起作用

这里。滚动后的头部行有一个额外的类.header-line .active,但css看不到它,并且不会改变背景颜色。你可以看到我的CSS,那里.header-line .active与background-color属性。为什么我的背景仍然透明?

CSS:

.header-line { 
    width: 100%; 
    height: 60px; 
    background-color: rgba(255,255,255,0.00); 
} 
.header-line .active { 
    background-color: white; 
} 

头:

<div class="header-line">header</div> 

的Javascript:

$(function() { 
    $(window).on("scroll", function() { 
    if($(window).scrollTop() > 50) { 
     $(".header-line").addClass("active"); 
    } else { 
     //remove the background property so it comes transparent again (defined in your css) 
     $(".header-line").removeClass("active"); 
    } 
    }); 
}); 
+1

请编辑和粘贴在这里的相关代码。无法从网页 – brk

+3

进行调试请在您的问题中包含任何相关的标记,JavaScript和CSS,请参阅:[我的网站或项目中的某些内容不起作用。我可以只是粘贴一个链接?](http://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste -a-link-to-it) –

回答

1

那是因为在你的CSS文件,你有.header-line .active { ... },这意味着.active类内部.header-line类。

你应该改变,要.headerline.active { ... }(删除空格)

+0

OMG谢谢。有效。 –

0

声明这样的CSS在你的bootstarp.css

.header-line.active { 
background-color: white; 
} 
相关问题