Scrolling past top with fixed navbar behaving differently across different browsers

McVenco

I'm encountering an issue with a fixed navbar in that I can't quite find an explanation or solution for.

When I scroll past the top of the page there is different behaviour in different browsers:

In Chrome (MacOS), the whole content scrolls down, like this:

enter image description here

In Safari (also Mac), the navbar stays fixed on top, and the background appears below it:

enter image description here

Ideally, I would prefer the behaviour as it is in Chrome. I have tried numerous approaches with using overflow, position, but I can't figure it out. Can I correct this behaviour with CSS (or perhaps Javascript/jQuery?)

Here's the bare bones of my code (the !importants are just here to override Bootstrap styling):

body {
    background-color: #eee !important;
    padding-top: 54px !important;
}

.navbar {
    min-height: 54px !important;
    border-bottom: 2px solid orange !important;
    margin-bottom: 0 !important;
}

.navbar-default {
    background: #fff !important;
    .navbar-brand {
        color: #000 !important;
    }
}

.usp-bar {
    background-color: orange;
    color: #fff;
    height: 30px;
    width: 100%;
}

.content {
  height: 800px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<body>

  <div id="app">

    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">
                    Navbar
                </a>
            </div>
        </div>
    </nav>

    <div class="usp-bar">
      orange bar
    </div>

    <div class="content">
      Content
    </div>

  </div>
</body>

Tom

Hacks

See puresamari's gist "overscroll background-color on ios" that places a fixed container in the negative space above the page. Doesn't work in Safari 11 or mobile Safari.

Overscroll-Behavior

Chrome 63 introduced the overscroll-behavior property that lets you disable scroll chaining or overscrolling altogether. However, still not supported in Safari ☹

Final Advice

The most reliable method is setting a background color on html and another on body, i.e. http://peter.coffee/htmls-background-color.

It's not yet possible to control how browsers overscroll, so instead set the correct colors and leave negative space at the top of the page for the fixed header.

Interestingly that's what StackOverflow does:

.top-bar {
    height: 50px;
}

.top-bar._fixed {
    position: fixed;
    min-width: auto;
}

.top-bar ~ .container, .top-bar ~ #announcement-banner {
    margin-top: 50px;
}

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 Fixed Top Navbar 'Flickering' On Mobile Scrolling using jQuery One-Page Scrolling Effect

From Dev

Bootstrap with navbar fixed top and Bootstro

From Dev

Smooth scrolling across browsers?

From Dev

Bootstrap navbar not fixed top for mobile

From Dev

Bootstrap 3 navbar-fixed-top after scroll past fullscreen hero unit

From Dev

JavaScript delete objects behaves differently in different browsers

From Dev

JQuery Position:Fixed 'NAVBAR' by scrolling the page

From Dev

How to stick table header(thead) on top while scrolling down the table rows with fixed header(navbar) in bootstrap 3?

From Dev

Top positioning in different browsers

From Dev

How to prevent different browsers rendering fonts differently?

From Dev

Code Behaving Differently On Different IDE

From Dev

Javascript smooth scrolling with fixed navbar offset

From Dev

Website Content disappearing behind fixed navbar with margin-top when scrolling

From Dev

scrolling an element on top of a fixed element

From Dev

how to make the navbar fixed to top

From Dev

Why regex in java is behaving differently for different example?

From Dev

Are cookies persistent across different browsers?

From Dev

Bootstrap with navbar fixed top and Bootstro

From Dev

Navbar stick to top of screen when scrolling past

From Dev

modulus behaving differently on different servers? (with / without spaces)

From Dev

fixed menu that is fixed after scrolling past a div

From Dev

How can I set a div to position:fixed, when scrolling it to the browsers top?

From Dev

bootstrap navbar fixed top and body padding top

From Dev

change navbar-fixed-top color when scrolling

From Dev

navbar-fixed-top sticking to top

From Dev

How to make a header fixed after scrolling past it

From Dev

Fix Bootstrap Navbar to top on scrolling

From Dev

jQuery position().top behaving the same as offset().top inside fixed parent

From Dev

The dl tag is shown in different browsers differently why?

Related Related

  1. 1

    Bootstrap 3 Fixed Top Navbar 'Flickering' On Mobile Scrolling using jQuery One-Page Scrolling Effect

  2. 2

    Bootstrap with navbar fixed top and Bootstro

  3. 3

    Smooth scrolling across browsers?

  4. 4

    Bootstrap navbar not fixed top for mobile

  5. 5

    Bootstrap 3 navbar-fixed-top after scroll past fullscreen hero unit

  6. 6

    JavaScript delete objects behaves differently in different browsers

  7. 7

    JQuery Position:Fixed 'NAVBAR' by scrolling the page

  8. 8

    How to stick table header(thead) on top while scrolling down the table rows with fixed header(navbar) in bootstrap 3?

  9. 9

    Top positioning in different browsers

  10. 10

    How to prevent different browsers rendering fonts differently?

  11. 11

    Code Behaving Differently On Different IDE

  12. 12

    Javascript smooth scrolling with fixed navbar offset

  13. 13

    Website Content disappearing behind fixed navbar with margin-top when scrolling

  14. 14

    scrolling an element on top of a fixed element

  15. 15

    how to make the navbar fixed to top

  16. 16

    Why regex in java is behaving differently for different example?

  17. 17

    Are cookies persistent across different browsers?

  18. 18

    Bootstrap with navbar fixed top and Bootstro

  19. 19

    Navbar stick to top of screen when scrolling past

  20. 20

    modulus behaving differently on different servers? (with / without spaces)

  21. 21

    fixed menu that is fixed after scrolling past a div

  22. 22

    How can I set a div to position:fixed, when scrolling it to the browsers top?

  23. 23

    bootstrap navbar fixed top and body padding top

  24. 24

    change navbar-fixed-top color when scrolling

  25. 25

    navbar-fixed-top sticking to top

  26. 26

    How to make a header fixed after scrolling past it

  27. 27

    Fix Bootstrap Navbar to top on scrolling

  28. 28

    jQuery position().top behaving the same as offset().top inside fixed parent

  29. 29

    The dl tag is shown in different browsers differently why?

HotTag

Archive