You should do it through JavaScript. You can either add a classname to the header element on scroll or just add/remove CSS with JS.
Something like this:
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$("header").addClass("add-shadow");
} else {
$("header").removeClass("add-shadow");
}
});
Refer to this for more info:
https://stackoverflow.com/questions/12558311/add-remove-class-with-jquery-based-on-vertical-scroll
Let me know if you have questions
I really appreciate your reply, but I am kind of non techy guy. I just want a css that can enable the shadow after user’s scroll down.
I have set the shadow but i don’t know how to start it when user scrolls down.
I want css
I believe you cannot do that unless you use some jQuery/JavaScript. Things like this are generally done through JavaScript since you cannot for example, know if the user has scrolled yet or not with just CSS.
I’m not too familiar with Elementor but just did some research and it seems like you can add your own custom CSS and JS to it as well.
Even if Elementor doesn’t let you add custom CSS and JS, you can install a plugin like this:
https://wordpress.org/plugins/custom-css-js/
So if no one else was able to answer this question with CSS only, you could do these steps:
1- Remove the shadow from header
2- Add a custom CSS class and add the shadow to it
Example:
.yourcssclassname {
box-shadow: 0 0 16px 0 rgba(0,0,0,.13);
transition: background 0.3s,border 0.3s,border-radius 0.3s,box-shadow 0.3s;
z-index: 3;
}
3- Put this code in your theme’s JavaScript file:
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
$("header").addClass("yourcssclassname");
} else {
$("header").removeClass("yourcssclassname ");
}
});
The value 50 is the number of pixels that a user will scroll before the shadow is added to the header element. You can increase/decrease that if you want.
Could you tell me the exact steps , I don’t know much about coding. Also the shadows are more professional in elementor pro. I just need to make it in such way that it only comes when User scrolls