Bootstrap > Affix

Horizontal-Affix menu bar in Bootstrap

How to create an horizontal affixed navigation menu in Bootstrap?


Affix 

The affix  allows a <div> to become affixed to a location on the page. You can also toggle it's pinning on and off using this plugin. A common example of this are social icons. They will start in a location, but as the page hits a certain mark, the <div> will be locked in place and will stop scrolling with the rest of the page.

<style>
        .affix {
            top: 0;
            width: 100%;
        }

            .affix + .container-fluid {
                padding-top: 50px;
            }
    </style>
</head>
<body>
    <div class="container-fluid" style="background-color:green;color:white;height:120px;">
        <h1>Bootstrap Affix Example</h1>
        <h3>Fixed navbar on scroll</h3>
    </div>
    <nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="200">
        <ul class="nav navbar-nav">
            <li class="active"><a href="#">SN ITFunda</a></li>
            <li><a href="#">DotNetFunda</a></li>
            <li><a href="#">TechFunda</a></li>
            <li><a href="#">ITFunda</a></li>
        </ul>
    </nav>
    <div class="container-fluid" style="height:1000px">
        <h1>DotNetFunda</h1>
        <p>DotNetFunda.Com is a popular online tutorials and guide for latest Microsoft® technologies aimed for beginners and intermediate level professionals. We help beginners to become intermediate level professionals and help intermediate level professionals to become an expert. By following our different sections regularly, we hope you will soon become one of the 'Most Valuable' professional and start shining in your career.DotNetFunda.Com is a popular online tutorials and guide for latest Microsoft® technologies aimed for beginners and intermediate level professionals. We help beginners to become intermediate level professionals and help intermediate level professionals to become an expert. By following our different sections regularly, we hope you will soon become one of the 'Most Valuable' professional and start shining in your career.DotNetFunda.Com is a popular online tutorials and guide for latest Microsoft® technologies aimed for beginners and intermediate level professionals. We help beginners to become intermediate level professionals and help intermediate level professionals to become an expert. By following our different sections regularly, we hope you will soon become one of the 'Most Valuable' professional and start shining in your career. </p>
        <h1>TechFunda</h1>
        <p>TechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step mannerTechFunda is a online tutorial to learn tutorials step by step manner</p>
        <h1>ITFunda</h1>
        <p>ITFunda is a online tutorial for online training and offline training and also provides ebooks for the people besides these ITFunda provides Job support for the people who are in need of the job supportITFunda is a online tutorial for online training and offline training and also provides ebooks for the people besides these ITFunda provides Job support for the people who are in need of the job supportITFunda is a online tutorial for online training and offline training and also provides ebooks for the people besides these ITFunda provides Job support for the people who are in need of the job supportITFunda is a online tutorial for online training and offline training and also provides ebooks for the people besides these ITFunda provides Job support for the people who are in need of the job supportITFunda is a online tutorial for online training and offline training and also provides ebooks for the people besides these ITFunda provides Job support for the people who are in need of the job support  </p>
    </div>
</body>
  • In the above code snippet we have defined the affix, In the body section we have defined the description in the div element by using class value container-fluid  and we have style in the div element 
  • In the next line of the body section we have nav element with class value as navbar navbar-inverse, data-spy="affix"  which makes the nav element fix to particular area and data-offset value as 200, we have the <ul> element to define the list values       
  • In the next line after creating nav element we have div section we have defined the div element with class value as container-fluid and we defined style, we have created description of DotNetFunda, TechFunda and ITFunda    
  • We have the style sheet in the head section of the html page to define the style of the affix and container-fluid. 

output

After scrolling the page appears as

 Views: 5013 | Post Order: 60



Write for us






Hosting Recommendations