Simple CSS Fixed Header

Posted by Cory Lamle - May 20, 2012 - Coding, Think Different, Tools, Videos - 37 Comments
CSS Fixed Header

Content is king when it comes to website traffic, however if your site doesn’t show well then you could be losing some of your audience or even business prospects.   When I visit a website and see a fixed item done correctly it usually stands out and my impression meter of the site automatically goes up even before I read the content.  Are you doing something to standout?

In this post we will run through how you can add a fixed header to your site and gain a visual distinction.   With less that 10% of all internet sites using fixed assets correctly, you can set yourself apart and allow your sites to have a different more elegant flow.

 Video Walkthrough  

Step 1: Locate Elements to Fix

The first thing to do is locate your target element(s) you want to set as fixed.  This is very easy with a DOM inspector like Google Chrome or Firebug.   To see how this is done visit the post Fast Website Layouts.  Once you have located the items place them inside a div element with an id such as: 

Step 2: Set CSS Styles

Once you have your items set as fixed you will need to most likely do some manual adjustments to the content inside the fixed div element.   Remember that fixed items work on an absolute layout so top, left, right and bottom are going to be very useful for getting the items positioned correctly.

If your header is large you can add an opacity (transparent) layer that will allow the content to bleed through the back.  This can be done by using the opacity setting in your CSS file.

Step 3: Validate Assets

Once you have your header fixed in position correctly you will want to make sure that other assets like videos and other fixed elements are accounted for when scrolling happens. In order to clean up videos from YouTube you can add the following script:

 Script Courtesy of MaxMorganDesing.com

It is also important to work with other fixed assets to make sure that they don’t collide with your new fixed header. Every site is going to be different so you will have to evaluate any other fixed assets you might have. Below is a script to adjust a WordPress plug-in called ShareBar. This script keeps my header from colliding with the ShareBar as the user scrolls. It also has some additional styling that gives the bar more of a  3-D feel.

 

Wrap-Up

So with a few simple adjustments of your header you can create a fixed layout that navigates easier and leaves a unique impression to those visiting your website!   Hope you enjoyed this article on setting up the fixed header.

What do you think?

Have you used fixed assets before?

This link as has been manually translated into Croation

Related Posts:

37 comments

Leave Reply

  • Nice. I primary use the fixed position bar at the bottom to display my latest special and affiliate links.

    Good to hear from you! ;)

    • Cory Lamle says:

      Yep, I think more people are realizing that proper placement on a site really gives them the edge they need keep important content in the users view.

      Thanks for touching base via the comments Terence!

  • Juan Timana says:

    I love this tutorial, thank you very much.

    • Cory Lamle says:

      Excellent! Thanks for touching base Juan… I hope do some more like this in the future.

  • Jewel says:

    Hi Cory,

    Really amazed.
    How can this type of fixed header affixed in blogger or wordpress site like my site (perfectnewgadgets.blogspot.com)

    I’m a new comer with just simple idea. So, please give me some specific knowhow, if possible.

    And, please, don’t laugh at my small and new site. It needs many scrutiny and refurbishment.

  • Jewel says:

    Hi Cory,

    Really amazed.
    How can this type of fixed header affixed in blogger or wordpress site like my site?

    I’m a new comer with just simple idea. So, please give me some specific knowhow, if possible.

    And, please, don’t laugh at my small and new site. It needs many scrutiny and refurbishment and many many qualitative contents also like yours.

    Thanks in advance.

    • Cory Lamle says:

      Hey Jewel,

      Thanks much! With Blogger or WordPress.com I’m not 100% sure if they expose access to your templates and PHP files. If they do then it should be pretty simple to add some css to those files. However if they don’t then you may not get the customization’s your looking for… You can easily take the source on this article and add it to your site, if they expose file access…

      Hope that help!

  • Jewel says:

    Thanks Cory,

    Blogger permits to add CSS to any blogs template. Unfortunately I’m unable to add any CSS to my blog. Maybe it needs assistance of a pro or maybe someday I’ll do it myself with proper knowledge.

    Thanks again for everything.

  • Juan Timana says:

    Hey Cory, BTW my site is now using this little trick you posted here, thanks a ton bro.

    • Cory Lamle says:

      Very nice Juan, I like it! The opacity looks really smooth. The forums area of the site is especially going to benefit when someone comes across a large thread. Excellent…

  • liliya says:

    So easy! Such a good example! You’re AWESOME!

  • Gregg says:

    Really informative video and related text tutorial! Very helpful.

    I’m not sure where to trouble shoot my issue: body elements partially hidden under the newly fixed header. Is there a way to “bump” content down so that they are clear of any fixed (in my case on top of page) elements?

    Thanks!

    Gregg

    • Cory Lamle says:

      Hey Gregg,

      Thxs for the feedback! Not 100% sure if I understand the issue, but I’ll give it a shot. On the body tag you should be able to set style=’margin-top:30px’ or something like that, you could also apply this style to a div tag that comes right after the body tag. This would help push any content initially below the fix element.

      Hope that helps!

  • Mat says:

    Hey I’m new to html- I tried using the tutorial, but could only get the header to stay fixed, and then the would keep moving. Any idea what I can do?

    Thanks,
    Mat

    • Cory Lamle says:

      Hey Mat,

      I checked out your site, it looks like the header is staying fixed correctly, at least in Chrome…

  • Mat says:

    hey ya i got it to work after some fiddling-thanks

  • nydene says:

    video is flows the fixed header.How to apply the above javascript

    • Cory Lamle says:

      For video overlays you can check out the video in the post source code, also you might have to do a google search for wmode=transparent to double check the various settings for the video player your using…

  • Al says:

    Hey Cory,

    1st: Very cool tip eh

    2nd: I’ve been trying to set this up on my mobile site to fix the header section. Worked but the rest of the content [div's] moved up behind the header logo. I see your javascript (above) says iframe, so assuming here (don’t like to assume eh lol) it is for video iframes.. and not content.. Would you know how I could fix it and push the page back down.. I really like the idea to keep my logo in front of the user.

    Thanks eh

    Take care,
    Al

    • Al says:

      Hey Cory,

      I read though the above again and must of missed it the first time but tried the suggestion you gave Gregg (style=’margin-top:30px’) and wouldn’t work so I tried padding-top:184px and that worked. Still needs a bit of tweaking and probably won’t use it on my mobile site (logo’s a bit big at 184px) but I will use it on a couple demo sites..

      Thanks again.

      Take care,
      Al

    • Cory Lamle says:

      Hey Al,

      Thanks for touching base! I see you got it going that’s great! As far as your original question on the iframe that is only for the video as the majority of most embeds (at least from the big guys, youtube, vimeo) mainly use the iframe. If your doing a responsive design site, you might check out one of these tools as they can help you with multi-platforms…

      Cheers!

  • Shawn Hazen says:

    Hey!

    Landed here while googling a fix for my problem. My site uses the method shown, but it breaks on the iPhone—specifically, if you try to zoom in, the header doesn’t zoom and everything gets all wonky.

    Any ideas?

    Thanks!

  • James says:

    Love the tutorial I have used it for my new design over at:
    http://www.listacker.com – Social Bookmarking!

    P.S Your shareoholic social bar does not appear to be working?

    Thanks

  • AK Ted says:

    Very nice walk-through! Noticed a typo. In step 3 (Validate Assets), it says
    Script Courtesy of MaxMorganDesing.com
    Should be design, not desing. And that link has a double http://.

    Thanks for the great tutorial!

  • AK Ted says:

    Very nice walk-through! Noticed a typo. In step 3 (Validate Assets), it says
    Script Courtesy of MaxMorganDesing.com
    Should be design, not desing. And that link has a double http://.

    Thanks for the great tutorial!

    Hrm. This comment form had an error on submittal, and said try again. Then said duplicate comment. Not sure if it went through. Sorry if it did.

  • kaiser harukari says:

    It’s so easy to integrate. I thank you for this. I just improved my design.

  • CJ says:

    i’m trying this effect and my problem is that the fixed div overlaps with the window scrollbars in IE. i works ok with firefox and chrome though

    how can i remedy this ?

    here is the page i am working on: http://www.cjmagowan.com/home

    • Cory Lamle says:

      Hey CJ,

      Thanks for stopping by! Nice site BTW… I’m not sure if I see any issues with your site, maybe shoot me a screen shoot of what issue your seeing?

      Cheers!

  • CJ says:

    hello Cory,

    It’s working fine now.. the problem that is cause by the css position property of the to “absolute”. now it’s fixed and following your tutorial is great..

    thanks

  • Samantha says:

    Hello!
    Your tutorial was good, but it didn’t solve my problem. All of my content that’s supposed to be BELOW my header and nav bar automatically jumps up behind it, so half of my content is hidden.

    • Cory Lamle says:

      Hey Samantha,

      Thanks for stopping by the site! You might have to do some manual adjustments, the code won’t be a one size fits all in some cases. You might want to double check the parent containers position and the z-index. Sometimes it takes a bit of fiddling to get it just right… Hope that helps a bit…

      Cheers!

  • Miguel B. says:

    Thanks for the great tutorial. I applied it to TheWeeklyRoundup.com

    Quick Question Thought.

    Where do we insert the Javascript in order to have videos hide behind the header.

    I.e. which file do I modify is it header.php or the stylesheet?

    • Cory Lamle says:

      Hey Miguel,

      For the JavaScript it will need to go into the header.php file.

      Hope that helps!

  • Nice blog here! Additionally your website a lot up fast! What host are you the use of? Can I get your associate hyperlink on your host? I wish my site loaded up as fast as yours lol

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Note: All comments are monitored!
We encourage users to only leave feedback if it values or encourages the other readers! We don't mind a short sales pitch for a product or your site if the link or text provides HIGH QUALITY content for the community. If your simply just trying to link build then your comments may get removed.

What your own custom image beside all your comments on every website? Sign up for a Gravatar. It free and it's easy!