Hi folks, I’ve strugged with the sticky header without javascript with adminbar support. After wrestling I got this code to work. Maybe I’ve missed something obvious? In any case, I wanted to share what worked for me, since you’ve been so helpful and I couldn’t find what worked for me. Maybe another user can make use of this.
Note: I’ve updated this with the response below.
/* sticky header & wpadminbar support */
#mobile-header,
#masthead {
position: sticky;
position: -webkit-sticky;
position: -top:0;
}
.admin-bar #mobile-header,
.admin-bar #masthead {
top: 32px;
}
@media screen and (max-width: 782px) {
.admin-bar #mobile-header,
.admin-bar #masthead {
top: 46px;
}
#wpadminbar {
position: fixed;
}
I use #mobile-header
and #masthead
depending whether there is a mobile header for the theme, so this code works on both kinds of sites.
Sometimes the #wpadminbar
gets a position:absolute;
so I override this.
I wrote up a more comprehensive description with various other options I encountered, which were less than satisfying: WordPress Adminbar Sticky