WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted

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 class

share|improve this answer
2  
This (incorrectly) affects all logged in users. Consider the answer by Brent instead. – Chris Burgess Jul 17 '12 at 11:06

Try adding this to your CSS file:

body.admin-bar #branding-wrap{top: 28px;} 
body.admin-bar #wrapper{margin-top: 145px;}

the body.admin-bardeclaration at the front will make sure that these styles only get applied when the admin bar is visible.

share|improve this answer
1  
body.admin-bar is the correct selector (and this the correct answer). Zach L's answer affects all logged in users, but only logged in users with content editing permissions have the admin bar visible and need the header moved down the page. – Chris Burgess Jul 17 '12 at 11:06
    
interesting... I've never personally had a setup with any users without these permissions. I imagine its the same as if in the user settings they disable the admin bar. – Zach Lysobey Jul 17 '12 at 15:43
    
Version note: .admin-bar is not longer appearing in WordPress 4. It's now called #wpadminbar and does not wrap the content, therefore the above cannot be applied to version 4+ – Raptor Feb 4 at 4:18

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!

<script>
( function(e) {
    var ab = document.getElementById( 'wpadminbar' );
    if ( typeof( ab ) === 'object' && window.innerWidth >= 610 ) {
        var abh = ab.offsetHeight || ab.clientHeight || ab.scrollHeight;
        var style = document.createElement( 'style' );
        style.id = 'adminbar_main_nav_controle_rules';
        document.getElementsByTagName( 'head' )[0].appendChild( style );
        var rules = document.createTextNode( 'body.admin-bar .main-navigation.fixed { margin-top: ' + abh + 'px !important; }' );
        style.appendChild( rules );
        console.debug( 'wpadmibar space is covered' );
    }
})();
</script>

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.