Bootstrap navbar overlapping content when using affix

mejobloggs

I want

  • A site banner with a navbar below
  • The banner to disappear when scrolling down, but the navbar to remain fixed

I found this jsfiddle which provides the above solution: http://jsfiddle.net/DTcHh/541/

Two main points of code:

//js
$('#topnavbar').affix({
    offset: {
        top: $('#banner').height()
    }   
});

//css
#topnavbar.affix {
    position: fixed;
    top: 0;
    width: 100%;
}

My problem now is when you scroll down to the point where the 'affix' happens. If you look carefully at that point it kinda jumps, and now the navbar is overlapping the first 4 lines in the paragraph

Any ideas how to get rid of that overlap?

Josh Crozier

You need to displace the fixed .navbar element by adding padding-top to the body element equal to the height of the fixed element.

You can listen to the affix.bs.affix/affix-top.bs.affix events and then determine whether the padding should be equal to the element's height or removed:

Updated Example - the jump you were seeing no longer occurs.

$('#topnavbar').on('affix.bs.affix affix-top.bs.affix', function (e) {
    var padding = e.type === 'affix' ? $(this).height() : '';
    $('body').css('padding-top', padding);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bootstrap 3 affix navbar becomes transparent and unclickable when scrolling and overlapping content

From Dev

Bootstrap Fixed Navbar Overlapping Content

From Dev

Twitter bootstrap 3: Navbar changes width when affix fires

From Dev

Bootstrap affix navbar scrollspy issue

From Dev

Using Affix in Bootstrap 2.3.2

From Dev

Bootstrap 3: Affix navbar fade in and add object

From Dev

Bootstrap Navbar Affix with Full-width Image

From Dev

Bootstrap Navbar Affix with Full-width Image

From Dev

dynamic bootstrap 3 navbar fixed top overlapping content

From Dev

How do you make it so the navbar is transparent then changes color using bootstrap 3. (Affix)

From Dev

Bootstrap affix taller than content, scroll fail

From Dev

Bootstrap grid elements overlapping navbar

From Dev

Bootstrap 4 navbar overlapping on mobile

From Dev

Bootstrap 3 - overlapping Content

From Dev

How to show div content in HTML when using BootStrap 3 navbar items

From Dev

How to show div content in HTML when using BootStrap 3 navbar items

From Dev

bootstrap affix navbar doesn't detect image height

From Dev

Bootstrap affix on navbar, property is always on (class always active)

From Dev

Bootstrap affix does not work when navigating back

From Dev

Switching bootstrap affix and affix-top class by scrolling make the elements below navbar move upward

From Dev

bootstrap: how to stylise navbar when using scrollspy?

From Dev

Bootstrap navbar content positioning

From Dev

Sync navbar content Bootstrap

From Dev

Bootstrap 3 - Overlapping Content (Clearfix?)

From Java

twitter bootstrap navbar fixed top overlapping site

From Dev

Overlapping Dropshadow in Bootstrap Navbar. That's bad

From Dev

how to affix div at top when we scroll down in bootstrap

From Dev

Bootstrap affix - Cant manage to hide image element when scrolling down

From Dev

Twitter bootstrap. Add a new class when class"affix" is added

Related Related

  1. 1

    Bootstrap 3 affix navbar becomes transparent and unclickable when scrolling and overlapping content

  2. 2

    Bootstrap Fixed Navbar Overlapping Content

  3. 3

    Twitter bootstrap 3: Navbar changes width when affix fires

  4. 4

    Bootstrap affix navbar scrollspy issue

  5. 5

    Using Affix in Bootstrap 2.3.2

  6. 6

    Bootstrap 3: Affix navbar fade in and add object

  7. 7

    Bootstrap Navbar Affix with Full-width Image

  8. 8

    Bootstrap Navbar Affix with Full-width Image

  9. 9

    dynamic bootstrap 3 navbar fixed top overlapping content

  10. 10

    How do you make it so the navbar is transparent then changes color using bootstrap 3. (Affix)

  11. 11

    Bootstrap affix taller than content, scroll fail

  12. 12

    Bootstrap grid elements overlapping navbar

  13. 13

    Bootstrap 4 navbar overlapping on mobile

  14. 14

    Bootstrap 3 - overlapping Content

  15. 15

    How to show div content in HTML when using BootStrap 3 navbar items

  16. 16

    How to show div content in HTML when using BootStrap 3 navbar items

  17. 17

    bootstrap affix navbar doesn't detect image height

  18. 18

    Bootstrap affix on navbar, property is always on (class always active)

  19. 19

    Bootstrap affix does not work when navigating back

  20. 20

    Switching bootstrap affix and affix-top class by scrolling make the elements below navbar move upward

  21. 21

    bootstrap: how to stylise navbar when using scrollspy?

  22. 22

    Bootstrap navbar content positioning

  23. 23

    Sync navbar content Bootstrap

  24. 24

    Bootstrap 3 - Overlapping Content (Clearfix?)

  25. 25

    twitter bootstrap navbar fixed top overlapping site

  26. 26

    Overlapping Dropshadow in Bootstrap Navbar. That's bad

  27. 27

    how to affix div at top when we scroll down in bootstrap

  28. 28

    Bootstrap affix - Cant manage to hide image element when scrolling down

  29. 29

    Twitter bootstrap. Add a new class when class"affix" is added

HotTag

Archive