Windows 10 reached EOS (end of support) on October 14, 2025. For more information, see this article.

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

此討論串已經關閉並封存。 如果您有需要幫助,請新增一個新問題

Skip link within page content not in viewport on focus in Firefox

更多選項

I have a skip link within my page content to allow keyboard users to skip a "quick links" section.

The content above the .skip div is long enough that the .skip div, the quick links div, and the #destination div are all below the bottom of the viewport when the page first loads.

The behavior that I would expect, and that I am seeing on Chrome, Safari, and Edge, is that when the anchor link inside the .skip div receives focus (in this case, when a user tabs to it), the entire link is visible in the viewport. In fact, in the non-Firefox browsers, it seems to center the focussed element in the viewport, which is ideal.

The issue seems to be just with Firefox (both on a Mac and a PC). The behavior I'm seeing in Firefox is that when the anchor link inside the .skip div receives focus, the top of the .skip div is at the bottom of the viewport, i.e. just off screen. If I scroll down the page, I can see that the .skip div and the anchor link inside it are visible and the anchor link has focus.

Any suggestions on how to replicate in Firefox the behavior seen on the other browsers? Thanks!

Here's a JSFiddle that replicates the issue: https://jsfiddle.net/ptdwkzgr/

I have a skip link within my page content to allow keyboard users to skip a "quick links" section. The content above the .skip div is long enough that the .skip div, the quick links div, and the #destination div are all below the bottom of the viewport when the page first loads. The behavior that I would expect, and that I am seeing on Chrome, Safari, and Edge, is that when the anchor link inside the .skip div receives focus (in this case, when a user tabs to it), the entire link is visible in the viewport. In fact, in the non-Firefox browsers, it seems to center the focussed element in the viewport, which is ideal. The issue seems to be just with Firefox (both on a Mac and a PC). The behavior I'm seeing in Firefox is that when the anchor link inside the .skip div receives focus, the top of the .skip div is at the bottom of the viewport, i.e. just off screen. If I scroll down the page, I can see that the .skip div and the anchor link inside it are visible and the anchor link has focus. Any suggestions on how to replicate in Firefox the behavior seen on the other browsers? Thanks! Here's a JSFiddle that replicates the issue: [https://jsfiddle.net/ptdwkzgr/ https://jsfiddle.net/ptdwkzgr/]

所有回覆 (4)

更多選項

If I inject the following into a page with basic links --

a {display: inline-block; min-height:72px;}

-- then Firefox does show nearly the entire 72px height of the link, but at the bottom of the viewport. If there is a trick for this, perhaps you can find it on StackOverflow or a developer's blog.

更多選項

@jscher2000 - Thanks for the suggestion, but it didn't work for me. If it helps to clarify, the simplified initial code looks like this:

HTML: <body> < div >A div with some content.< /div > < div >A div with some content.< /div > < div class="skip" > <a href="#destination">Skip quick links navigation</a> < /div > < div >Quick links navigation.< /div > < div id="destination" >A div with some content.< /div > < div >A div with some content.< /div > < div >A div with some content.< /div > </body>

CSS: .skip a {position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden;} .skip a:focus {position: static; width: auto; height: auto; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 4px solid #0067a5; color: #0067a5; display: block; font-size: 1.75em; line-height: 1.1; padding: 1em; text-align: center;}

I tried editing the CSS to add display: inline-block; min-height: 72px;, first to .skip a and then to .skip a:focus. Neither worked, the .skip div with focus was still just offscreen in both cases.

更多選項

Yes, I'm not surprised because I couldn't figure out a fix. I don't know how absolute positioning and floats affect the way Firefox calculates the vertical scroll position of the link, and you also have padding.

更多選項

This question has been locked because the original author has deleted their account. While you can no longer post new replies, the existing content remains available for reference.