I’ve styled my header to have a fixed top position. While logged in to wordpress, the wp admin nav bar covers the top section of my header making imposible to access my top navigation. I would like for the wp admin nav to push my top navigation below so both are visible. Does anyone know of any solution to fix this problem?
An example of my problem can be found at…
www.nickriversdesign.com/dev
in your css you could try something like:
body.logged-in{margin-top:20px;}
or if this doesnt work some other code using the.logged-in
classTry adding this to your CSS file:
the
body.admin-bar
declaration at the front will make sure that these styles only get applied when the admin bar is visible.Try this for WordPress 4+. It checks if the admin bar is present and if so move the fixed header down a bit to compensate.
This works as well
I believe, on devices with smaller widths, wpadminbar is not positioned fixed. So if you scroll the document in a smartphone, the admin bar will follow the scroll and will not stay at the top of the window. With keeping this in mind, why not add some javascript in the footer of your theme just after the
wp_head()
call. This way we can target the device width and whether or not the document has the adminbar. Then simply make some CSS rules and append it to the document head – like below!Assuming your nav has a class
'main-navigation'
and on scroll you add another class named'fixed'
to it. Change the CSS to target your navigation panel by replacing'body.admin-bar .main-navigation.fixed'
with howsoever you would want to target yours.It can be further improved for example checking if the admin bar is fixed or not, but for now, I hope it will helps.
I just used this CSS.
I read all answers but didn’t find that one:
Why not use wp function:
example header.php theme file
Try this, it is works fine
give the top navbar