Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a sticky left sidebar menu using bootstrap 3?

I want to create a left-sticky bar menu with bootstrap 3 like:

http://getbootstrap.com/getting-started/

I'd read the given documentation http://getbootstrap.com/javascript/#affix

I try with .affix but the result is zero.


Update: @Skelly,
Thanks for your kind example. and yes, I want like your example. I'd download your example html, but after download the html file's side bar didn't work there.

like image 604
Sohag-Monist It Avatar asked Oct 30 '13 12:10

Sohag-Monist It


People also ask

How do I make my sidebar sticky?

You can either make a custom stylesheet specifying the sidebar style or you can add an inline CSS code "position: sticky" to your sidebar element/container.

What is a sticky sidebar?

A sticky sidebar ad remains in the same relative position when users scroll down the page. It's a great way to take advantage of your page design to boost your overall ad revenue, especially on longer posts.

Does bootstrap have sidebar?

Basic exampleOfficial Bootstrap documentation does not contain a Sidebar component, but it's possible to create fully-functional side navigation from the existing components, and with the little help of Material Design for Bootstrap - free and powerfull UI KIT.


2 Answers

Bootstrap 3

Here is a working left sidebar example:

http://bootply.com/90936 (similar to the Bootstrap docs)

The trick is using the affix component along with some CSS to position it:

  #sidebar.affix-top {     position: static;     margin-top:30px;     width:228px;   }    #sidebar.affix {     position: fixed;     top:70px;     width:228px;   } 

EDIT- Another example with footer and affix-bottom


Bootstrap 4

The Affix component has been removed in Bootstrap 4, so to create a sticky sidebar, you can use a 3rd party Affix plugin like this Bootstrap 4 sticky sidebar example, or use the sticky-top class is explained in this answer.

Related: Create a responsive navbar sidebar "drawer" in Bootstrap 4?

like image 129
Zim Avatar answered Sep 21 '22 12:09

Zim


You can also try to use a Polyfill like Fixed-Sticky. Especially when you are using Bootstrap4 the affix component is no longer included:

Dropped the Affix jQuery plugin. We recommend using a position: sticky polyfill instead.

like image 21
H6. Avatar answered Sep 20 '22 12:09

H6.