0

Can please someone help me?

Here .header-line after scroll has an additional class of .header-line .active but css can't see it and doesn't change the background-color. You can see my css and there .header-line .active is with background-color property. Why is my background still transparent?

CSS:

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

header:

<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");
    }
  });
});
2

2 Answers 2

6

That is because in your css file you have .header-line .active { ... }, and that means .active class inside .header-line class.

You should change that to .headerline.active { ... } (remove the space)

Sign up to request clarification or add additional context in comments.

1 Comment

Not sure why the question got voted down. It's a perfectly valid question, representing the same problem I came here to find an answer for, and with this answer, I found it. SO's voting system is irreversibly broken, IMO. Thanks! This solved the same problem for me.
0

Declare the css like this in your bootstarp.css

.header-line.active {
background-color: white;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.