小编Dar*_*eer的帖子

当 Chrome 中 html 标签上的滚动行为设置为“平滑”时,HTML5 表单验证消息不会显示

scroll-behaviour:smooth当使用 HTML5 验证的页面上存在表单字段时,我在 html 标记上设置属性时遇到冲突。使用 Chrome 时您可能会看到此问题(在 Firefox/Safari 中正常)

如果第一个错误字段位于视口之外,则在验证时,文档会向上滚动并聚焦在该字段上,但不会显示错误消息。

我已经设置了下面的基本代码。注意:使用 Codepen、JSFiddle 等时不会出现此问题。

<!DOCTYPE html>
<html lang="en">
    
    <head>
      
        <meta charset="utf-8">
        <title>Scroll Behaviour / Form validation Issue</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <style>
            html, body {
                scroll-behavior: smooth;
            }

            p {
                margin-bottom: 1200px;
            }
        </style>
      
    </head>

    <body>

        <h3>Scroll behavior / From validation issue</h3>

        <form id="frm-enquiry" action="?">
            <fieldset>

                <label for="first-name">First name</label>
                <input id="first-name" type="text" required />

                <p>Scroll down to submit button and click. If scroll occurs then no error message is shown. …
Run Code Online (Sandbox Code Playgroud)

html css forms validation smooth-scrolling

18
推荐指数
1
解决办法
2728
查看次数

标签 统计

css ×1

forms ×1

html ×1

smooth-scrolling ×1

validation ×1