HTML5 input required, scroll to input with fixed navbar on submit

前端 未结 9 2142
感情败类
感情败类 2020-12-08 09:35

When trying to submit a form with missing required fields, my browser (Chrome), displays a message mentionning there is a field missing, and if it\'s out of my screen, it sc

9条回答
  •  醉话见心
    2020-12-08 10:04

    In modern browsers there is a new CSS property for that use case:

    html {
        scroll-padding-top: 50px;
    }
    

    Your JSFiddle updated: http://jsfiddle.net/5o10ydbk/

    Browser Support for scroll-padding: https://caniuse.com/#search=scroll-padding

提交回复
热议问题