html - 加载 HTML 文件时浏览器跳转到页面中间

标签 html

当我在 Chrome 中打开 HTML 文件时,页面从文档中间(请参阅下面代码中的最后一个 h3 标签)加载一些随机的 h3 标签,而不是页面的实际顶部.该点以上的所有内容都是负载,但我必须向上滚动才能到达顶部。

当我使用 Firefox 时会发生同样的事情,尽管在我的示例中它会在窗口顶部加载第一个 h3 标记。 Safari 在顶部加载“这是一个粗体文本示例”段落。知道为什么会发生这种情况吗?

<h3>Audio</h3>
<audio src="07 Wake Up.mp3" controls>Here is some audio</audio>

<p>
<a href="#top">Back to top</a>
</p>

<hr />

<h3 id="B">Bold text</h3>
<p>Here is an example of <b>bold text</b></p>

<h3>Bi-directional override</h3>

<p><bdo dir="rtl">This text will go from right to left.</bdo></p>
<p><bdo dir="rtl">.tfel ot thgir morf og lliw txet sihT</bdo></p>

<h3>Blockquotes</h3>

<p>Blockquotes specify a section that is quoted from another source, like in the passage below:</p>
<blockquote cite="http://www.archives.gov/exhibits/charters/declaration_transcript.html">We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.</blockquote>

<h3 id="button">Buttons</h3>

最佳答案

我想我知道现在发生了什么。问题不在于页面顶部正在加载的标签,而是出现在几行下方的自动对焦按钮:

<h4>Autofocus button</h4>
<button type="button" autofocus>Autofocus button</button>

对于任何玩弄自动对焦按钮的人来说,似乎它们会导致浏览器在加载时“自动对焦”(duh) 那个点。在我原来的情况下,我的页面加载了窗口底部的自动对焦按钮,顶部几行的一些标题,页面的实际顶部看不到。

关于html - 加载 HTML 文件时浏览器跳转到页面中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35471263/

相关文章:

javascript - 如何编码传递给 div.load() 的 URL?

java - TD 在运行时扩展

html - 用css颜色替换图片并根据内容调整大小

javascript - 如何根据JSON文件在D3 Javascript库中绘制节点

javascript - 是否可以输入 CSS 边框

html - CSS - 在下拉列表周围填充

html - .col 周围的包装 div 没有高度?

jquery - CSS hover 轻拂下图

javascript - 滚动回页面顶部时,Data-spy 不会重新突出显示 "Home" anchor

javascript - 如何以适当的方式获取表标签的td标签