Mobile Number Tracker
Trace Mobile Number Earn Money Online

Create Floating Bar Like Gmail and Facebook

Samyak Lalit | March 14, 2012 (Last update: September 22, 2017)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

Nowadays, use of floating bars is common in web designs. As far as I remember, Google and Facebook were the first among the prominent websites to have used such a floating bar. If you’re wondering what is a floating bar, well, it is basically a DIV element that stays st fixed position all the time. Even if website visitor scrolls the page, the floating bar remains fixed. This helps in constantly keeping certain content in user’s view.

Many people ask me about how to create a Facebook like floating bar. Although it is a bit jerky but the technique quite useful in keeping certain portion of the web page always in front of user’s eyes.

Floating Bar on the Sides, Top or Bottom

It is pretty easy if you want to create a floating bar that touches any of the screen edges, left, right, top or bottom. Just create the bar using a DIV element and float it using position:fixed CSS rule. In addition, you can use right: 0 and bottom: 0 for placement of your bar. For example:

position: fixed;
bottom: 0;

This CSS code will give you floating bar placed at the bottom edge of the screen.

Floating Bar in the Middle of Webpage

Use the following method if the portion-to-be-floated is located somewhere in the middle of the web page and you want to make the bar float only when user scrolls the screen.

IMPORTANT: This technique makes use of jQuery. Your website must include jQuery library before you use this technique. WordPress and many other CMS already come loaded with jQuery. Check the documentation of you blogging or CMS platform.

If your website does not have jQuery -paste the following line in the HEAD section of your webpage to include the library:

<script type="text/javascript" src=""></script>

This code fetched the jQuery library from Google servers and load as part of your web page.

Now here are the codes for creating floated content.

HTML code

<div id="my-float-container">
    <div id="my-float">
...content comes here...

CSS rules

#my-float-container {
...define styles like width and height for container...

#my-float {
overflow: hidden;
z-index: 1;
...keep the above two styles and add more as need be...

#my-float.floating {
    position: fixed;
    top: 0;
    box-shadow: 0 4px 2px -1px rgba(0, 0, 0, 0.25);
    -moz-box-shadow: 0 4px 2px -1px rgba(0, 0, 0, 0.25);
    -webkit-box-shadow: 0 4px 2px -1px rgba(0, 0, 0, 0.25);

JavaScript code

$(document).ready( function() {

    $(window).scroll( function() {
        if ($(window).scrollTop() &gt; $('#my-float-container').offset().top)
    } );

} );

That’s it!

Enjoy the floating content! BUT let me advise you not to put AdSense ads in such floating segments -because this is against AdSense policy.

I hope this was useful for you. Please feel free to ask if you have any questions on this topic. I will be happy to try and help you. Thank you for using TechWelkin.


One response to “Create Floating Bar Like Gmail and Facebook”

  1. Kathy Davie says:

    If I incorporate this, will my main text float around the div? I want to use a floating menu specific to a page or post, but I hate it when the box covers up text. I’d like the text to flow around the box as the page moves.

Leave a Reply

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