HTML 5自动对焦会混乱CSS加载

问题描述 投票:12回答:1

当我在输入元素上设置autofocus="autofocus"时,然后在Firefox中,当页面加载时,它会在没有应用CSS的情况下显示一瞬间。 (例如,内容不居中,标题以默认字体等呈现)

如果我删除自动对焦,页面会正常加载并在准备就绪时显示。

在Firefox中使用autofocus功能时,有没有办法让页面正常加载?

html css html5 firefox autofocus
1个回答
15
投票

我发现通过在<head>中添加一些JavaScript,页面等待在焦点之前加载样式。

我不确定为什么会这样,但确实如此!

例:

<script type="text/javascript">
    // Fix for Firefox autofocus CSS bug
    // See: http://stackoverflow.com/questions/18943276/html-5-autofocus-messes-up-css-loading/18945951#18945951
</script>
© www.soinside.com 2019 - 2024. All rights reserved.