How to use Bootstrap Affix Plugins

BootstrapWeb DevelopmentCSS Framework

The affix plugin 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.

The affix plugin toggles between three classes, each representing a particular state − .affix, .affix-top, and .affix-bottom. Follow the below steps to set your CSS for either of the above usage options.

  • To start, the plugin adds .affix-top to indicate the element is in its top-most position. At this point, no CSS positioning is required.
  • Scrolling past the element you want affixed should trigger the actual affixing. This is where .affix replaces .affix-top and sets position: fixed; (provided by Bootstrap's code CSS).
  • If a bottom offset is defined, scrolling past that should replace .affixwith .affix-bottom. Since offsets are optional, setting one requires you to set the appropriate CSS. In this case, add position: absolute; when necessary.
Published on 21-Jun-2018 06:56:52