November 26, 2007

Dropdown Navigation Bar For Blogspot

Last update: 2008-02-13

There are many tricks to remove the Blogspot Navigation Bar (or "NavBar") that is displayed on top of all Blogger blogs. The simplest would be to add the following CSS declaration to the bottom of the "skin" section of your template (i.e. in between the <b:skin> and </b:skin> tags):
#navbar{
    display:none !important;
}

Besides the question if this approach violates the Blogspot "Terms of Use", this will leave people who are flipping through blogs via the "next blog" link lost. Additionally, as blog editor, you loose your shortcut links to sign in and post new messages.

Why not hide it, but still keep it accessible, more or less like a dropdown menu. To achieve this, add the following code to your template, or add it to your blog layout as a html/javascript page-element:
<!-- DROPDOWN NAVBAR -->
<!-- stylesheet for FF2, Op9, IE7 (strict mode) -->
<style type="text/css">
#navbar {
display:inline;
width:100%;
position:absolute;
background-color:transparent;
top:-30px;
left:0px;
height:60px;
z-index:999999;
}
#navbar:hover{
top:0px;
height:30px;
}
</style>
<!-- stylesheet for IE6 and lower -->
<!-- (not supporting element:hover) -->
<!-- first, unhide the navbar through css -->
<!-- second, hide the navbar and mimic -->
<!-- the effect with javascript, if available -->
<!--[if lt IE 7]>
<style type="text/css">
#navbar {
height:30px;
top:0px;
}
</style>
<script type="text/javascript">
var navbar = document.getElementById('navbar');
if(navbar){
navbar.onmouseover = function(){
navbar.style.top = '0px';
navbar.style.height = '30px';
}
navbar.onmouseout = function(){
navbar.style.top = '-30px';
navbar.style.height = '60px';
}
if (navbar.captureEvents){
navbar.captureEvents(Event.MOUSEOVER);
navbar.captureEvents(Event.MOUSEOUT);
}
navbar.onmouseout();
}
</script>
<![endif]-->
<!-- end dropdown navbar -->

Now, the navbar is shifted up, with its content outside the viewport frame and thus out of sight for the user. The navbar is doubled in height, with an empty, transparent part still invisibly dangling at the top of the viewport. When the mouse cursor hovers over the empty part of navbar, the navbar is repositioned into its normal position and the doubled height is removed. When the mouse cursor leaves the navbar, the styling is reaplied and the navbar hides itself again.

You can see this effect in action on this page, just scroll to the top of the page and move your mouse to the top of the viewport.

The mouseover effect is achieved by applying a :hover pseudo-class to the navbar element. This works in Firefox 2.0, Safari 3.0 Win, Opera 9.5b, iCab 3.0, Konqueror 3.5.7 and Internet Explorer 7, although the latter only when rendered in strict mode. For older IE browsers (or possibly IE 7 in quirks-mode), a javascript fallback is activated through a conditional comment that is only visible to Internet Explorer 6 and lower. When javascript is disabled the navbar will not be hidden.



Note: Most blog templates have a strict doctype declaration (second line in the template), which is fine. If you are rendering your page in quirks mode (i.e. dtds Transitional or Loose), you need to change the conditional comment to [if lte IE 7].



I chose to position the navbar over my design (position:relative), if you don't want it to overlap with your design, change the position to static.

Update: It is not against Googles Terms Of Service (TOS) to hide the NavBar. The Real Blogger Status blog posted a link to an answer to this question from a google employee.

13 comments:

  1. thank u
    it is very helpful
    but can u give me the code by which i can show HTML codes in my blog , as that tables which i see in ur blog
    i tried ( textarea ) but i dont like it

    thanx in advanced

    ReplyDelete
  2. To show HTML code on my blog, I use the <pre> tag which I styled through CSS:

    pre{
    color:#000000;
    background-color:ghostwhite;
    border:1px dotted dimgray;
    padding:2px;
    overflow:auto; /* */
    overflow-y: visible; /* IE bugfix, IE property only */
    width:98%;
    }

    To prevent the browser from seeing the HTML code you want to show as actual HTML, you have to convert the HTML characters to special characters. You can do so on this page: http://www.chrishardy.co.uk/asp/tools/html-special-character-converter.asp

    Hope this helps.

    ReplyDelete
  3. Hi Erie,
    Thank you for the codes.
    But I'm having problem adjusting the navi bar position.
    I opened a testing blog to test the code, it came out strangely.
    Please click my link , I would like to know whatthe problem is.
    Thank you very very much!

    ReplyDelete
  4. @ Candice:

    I didn't check what actually causes the navbar to jump halfway to the right of the screen in your template, but it's easily fixed by adding a single statement to your css.

    #navbar{
    left:0px;
    }

    I updated the provided solution in this post to include this fix.

    ReplyDelete
  5. looks good, but where would it go in the edit HTML Layout?

    ReplyDelete
  6. Really impressive!

    Are you sure that hiding the navigation bar of blogspot in this dropdown fashion doesn't violate Blogspot's "Terms of Use"? If not, I would like to use your trick.

    I've used your code though a page element. It worked.

    But when I tried to use your code by pasting it just before the "Variable definitions" of HTML code, the trick didn't work. The navbar shifted a bit lower and there was a sign like --> in the middle of the blank space above the navbar.

    ReplyDelete
  7. @ahmad:
    "Sure" would be when I won a lawsuit filed against me by Google. Which is probably never. They'll probably never file a lawsuit, and if they do, I'll probably never win it :-)
    But in my defense I would say that this 'trick' doesn't render the navbar unusable at all, plus there are plenty blogs out there that hide it completely. As long as your blog doesn't have too many visitors, you'll stay well below their radar.

    If you don't want the code for this effect in a html/javascript page element, you can indeed insert it in the page template. But that requires some basic knowledge of the HTML language. The easiest would be to place the code snippet just before the closing tag of the page 'head':
    </head>
    Hope that helps!

    ReplyDelete
  8. Thanks Erie :-) . It worked with the HTML code in template.

    But one thing I noticed that the navbar covered some portion of the header when I hovered mouse over there. How can we leave some blank space above the header so that when we hover mouse over, the navbar fill up the space but doesn't cover some portion of header? Would you please tell us?

    --- Ferdous

    ReplyDelete
  9. You can add the folling CSS statement to the dropdown-navbar code snippet, right before the </style> tag:

    body {margin-top:30px;}

    This will make everything on the page shift down by 30 pixels, to make a space to hold the navbar.

    That should do the trick. Good luck with your final exams! ;-) Spend your time wisely!

    ReplyDelete
  10. Thanks! This worked perfectly! :)

    ReplyDelete
  11. Thank you very much, it really helped me a lot! My page is now a little less annoying! ^_^

    ReplyDelete