I’ve made three small changes to your codepen, and it seemed to work as you want it to:
1- Navbar height is created in class ". navbar" and not in ". nagivation".
.navbar {
height: 100px;
min-width: 100%;
background-color: rgba(0, 255, 0, 0.5);
display: table;
table-layout: fixed;
-webkit-transition: all 0.4s ease;
transition: all 0.4s ease;
}
2- I created the ". Sticky" class separately (you can create it together with the others later, but I think it’s best to have it alone first).
.sticky{
background-color: rgba(255, 0, 0, 0.8);
visibility: visible;
height: 40px !important;
}
3-In Js file I selected the class ". navbar", which is where the class ". Sticky" will be inserted
$(window).scroll(function() {
if ($(document).scrollTop() > 50) {
$('.navbar').addClass('sticky');
} else {
$('.navbar').removeClass('sticky');
}
});
Obs: I changed the colors of the bars . Sticky and . navbar, to have a better perception of what was going on.