HTML 5自动对焦会混乱CSS加载
When I set autofocus="autofocus"
on an input element, then in Firefox, when the page loads, it displays for a split second without the CSS applied. (E.g. content not centered, heading rendered in default font etc.)
当我在输入元素上设置autofocus =“autofocus”时,在Firefox中,当页面加载时,它会在没有应用CSS的情况下显示一瞬间。 (例如,内容不居中,标题以默认字体等呈现)
If I remove the autofocus, the page loads fine and displays when it is ready.
如果我删除自动对焦,页面会正常加载并在准备就绪时显示。
Is there a way to get the page to load normally while using the autofocus
feature in Firefox?
在Firefox中使用自动对焦功能时,有没有办法让页面正常加载?
1 个解决方案
#1
14
I have found that by adding some JavaScript in the <head>
, the page waits for the style to load before the focus.
我发现通过在中添加一些JavaScript,页面等待在焦点之前加载样式。
I'm not exactly sure why this works, but it does!
我不确定为什么会这样,但确实如此!
Example:
<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>
更多相关文章
- Web前端-html页面-做过的一个公司的主页
- html页面中给img标签的src属性赋值为一张图片的存储路径,图片不显
- 加载跨域的HTML页面AJAX
- HTML5,简单的注册页面
- 在页面重新加载时添加活动链接和jquery幻灯片切换到自定义ajax w
- 使用HTML5 canvas做地图(3)图片加载平移放大缩小
- 使用img src加载图像会在Mozilla / Chrome中产生不同的大小
- 分叉开源PHP代码,项目类加载器策略
- PHPCMS V9 的手机门户wap绑定单页面