3

The problem (Excess White Space Above Admin Bar on Frontend Using Twitter Bootstrap):

While logged in and viewing the frontend -- If you shrink your browser down, there is an excess amount of white space which appears ABOVE the admin bar. I've noticed it's fine in full screen, and even ~tablet size. However, when about to shrink to anything smaller than about 600px, that's when the white space appears ABOVE the admin bar. I have tested on my phone, and the white space is there on my phone too.

The Question:

Is this a conflicting issue with WordPress, or is there something I need to do with my Twitter Bootstrap setup?


Any advice on eliminating this excess white space above the admin bar while viewing the frontend (using Twitter Bootstrap -- Responsive) on a mobile device would be greatly appreciated.

2 Answers 2

10

I just ran into this issue as well, the cause of this is that at 600 pixels wide the admin bar goes from being position:fixed to position:absolute;

When fixed, it is locked to the top of the screen (top:0)

When absolute it is locked to the top of the closest container that contains it. This is the html element by default, but if a parent is defined to have a position, (in our case body has a position definition) then it will contain all of its children, and their position rules will be based off of its position. Since the html element has a margin-top of 46 pixels, it pushes the body down by 46 pixels. So since the body is pushed down by 46 pixels, the best our admin bar can achieve is the top of our body not the top of the page.

If you need to have position:relative on the body then you can do a couple of things to get around this. You can add either of these rules to your themes css file and it'll overwrite the default wordpress css.

  1. You can override the admin bar position absolute rule, and flip it back to fixed. This will make the admin bar scroll with the page so that you always see it at the top no matter where you are on the page.

    html #wpadminbar{position:fixed};

  2. You can change the position of the admin bar to have a top of -46px in resolutions under 600px; This keeps the bar at the top of the page on small screens so that it doesn't take up screen realestate as you scroll around.

    @media screen and (max-width:600px){html #wpadminbar{top:-46px}}

1
  • If I had $5 for every time I've fixed this on a Bootstrap or Foundation based WordPress theme, I'd probably have to report the taxable income to the IRS. Commented Mar 24, 2015 at 16:40
0

It was something simple. I had position: relative; set for the body.

Example:

body {
    position: relative;
}

I have no idea WHY that would effect it, but eliminating position: relative; for the <body> tag fixed that excess white space above the admin bar on the frontend while browser size is < 600px.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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