On Safari Mobile 10.3 sticky footer can be scrolled off the screen

前端 未结 3 2126
走了就别回头了
走了就别回头了 2021-02-11 17:19

Our mobile web application has sticky bottom navigation like the one you often find in iOS applications, and after Safari 10.3 release on landscape only it is p

3条回答
  •  爱一瞬间的悲伤
    2021-02-11 17:35

    There is another way of creating a fixed element at the bottom of the page:

    Set the element (or whatever wraps your header, content and footer) to display: flex; height: 100vh. Then you take the footer and set it to margin-top: auto.

    HTML:

    
        

    CSS:

    html {
        height: 100%;
    }
    
    body {
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    main {
        flex: 1;
    }
    

    A different solution with the same markup would be to use CSS Grid:

    html {
        height: 100%;
    }
    
    body {
        height: 100%;
        display: grid;
        grid-template-rows: auto 1fr auto;
    }
    

    In order to get the best of both worlds you can wrap the CSS Grid styles in an @supports(display: grid){} wrapper. If Grid is supported the browser will take that and otherwise will fallback to Flexbox.

    The best thing using this technique is that you won't run into overlapping contents, into zooming-issues and it is fully responsive from the get-go.

    There is an article on CSS Tricks about the subject: https://css-tricks.com/couple-takes-sticky-footer/

提交回复
热议问题