Anchor positioning within Firefox Mobile (for Android)

I created a homepage with multiple sections, each linked to from the main menu:

<body>
    <header>
        <!-- nav used on all pages -->
        <a href="#nav" class="toggle-nav">
            menu <i class="fa fa-bars"></i>
        </a>
        <nav class="main-nav" id="nav">
            <a href="/#item1">Link</a>
            <a href="/#item2">Link</a>
        </nav>
    </header>


    <!-- homepage -->
    <main>
        <section id="item1">some content here </section>
        <section id="item2">some other content here </section>
    </main>
</body>

Maybe this css is relevant:

body {
    position: relative;
    overflow-x: hidden;
}

@media only screen and (max-width: 750px) {
    header .main-nav a {
        display: block;
    }

    .tiggle-nav {
        display: none;
    }
}

The goal is for users to click on 'Item 1' in the menu and be taken directly to that section of the homepage.

This setup works perfectly, except on firefox mobile. When clicking the internal anchor link from any other internal page, the homepage loads anywhere from 100 to 200px off the mark.

Interestingly, refreshing the page after initially loading allows firefox mobile to find the internal anchor correctly. This issue seems exclusive to navigating from an internal page to the homepage.

What could be causing this problem? Is there a delay in loading CSS on firefox mobile until it locates the internal anchor?

Most importantly, how can I ensure firefox mobile lands on the correct location right away?

Any insights would be greatly appreciated.

View the full css and html live at

Answer №1

To fix the issue, modify the main.js file by changing 400 to 0 in the section below:

$('#top').click(function(e) {
    e.preventDefault();
    $('body,html').animate({scrollTop:0},400);
});

After the adjustment, the code should appear as follows:

$('#top').click(function(e) {
    e.preventDefault();
    $('body,html').animate({scrollTop:0},0);
});

I have tested this change and it appears to resolve the problem. The likely reason for this is that the extra 400 pixels previously added above the anchor link are no longer included.

Answer №2

To replicate the issue, I followed these steps:

First, I navigated to the connect page and selected "Writing". The positioning was off at this point. Next, I turned off JavaScript so that the anchor could be relied upon for navigation, which resolved the issue.

In order to address this issue in a more permanent way, I implemented a solution where a specific element on the page is identified to determine whether to use JavaScript scrolling or direct anchoring.

if (document.getElementById('homepagebookmark')){
  //scroll with JavaScript
} else {
  //maintain current behavior
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to locate a div element using CSS selector in Selenium WebDriver with Ruby

My experience with CSS selectors in selenium webdriver has been positive, but I am facing difficulty in locating the element within the following div. <div class="class1 class2" dd:btnfloatingstyle="top-right" dd:entitytexttype="resultval" id="_78891a3 ...

Creating a bottom bar using React and Material UI

I'm currently working on implementing a footer that will be displayed on every page of my Next.js application. To style this, I am utilizing Material UI. The following component is responsible for defining the layout across all pages of the app: impo ...

The CSS dropdown navigation bar designed for mobile devices functions properly, however, it is not visible on iPhones

After building this website from scratch using only HTML and CSS, I encountered an issue with the dropdown menu not appearing on iPhones. Despite testing it extensively across different browsers and devices, the problem persists on Apple products. While i ...

Conceal User Interface Angular Tabulation

I'm working on setting up UI Bootstrap tabs, and for reference you can find the plunker here. My goal is to hide the tabs since I will be utilizing a button to switch between them. Despite adding the following CSS class to my file, the styling is not ...

Constantly centered div

I'm dealing with a situation like this: .center_position_div{ width:100%; background-color:green; display: flex; flex-wrap: wrap; } .show_running_exam { width: 22%; background-color:aliceblue; margin-left: 1%; margi ...

SVG is not extending to the entire viewport in mobile view

I need help with adjusting wave SVG's on my website to fill the entire viewport or screen width. Does anyone have any suggestions? To create the waves, I used a Wave SVG generator and placed them within a div element. <nav> <div> //align ...

Tips on toggling the visibility of a div using jQuery and CSS via a toggle switch

Hey there, I need some help with toggling the opening and closing of a div when clicking on a toggle switch. $('.tog').on('click', function() { $('.cntr').show(); }); .switch { position: relative; display: inline-bloc ...

Can you guide me on implementing a transition animation through class toggling?

I am facing an issue where certain elements need to be highlighted or unhighlighted conditionally. To achieve this, I have assigned a class called highlight to the elements that require highlighting with a transition animation. The challenge arises when t ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...

Having issues with the background-image style not displaying correctly in the header of an

Trying to update the "background-image:" of a CSS class upon button click. JQuery: $(function() { $('button').on('click', function() { $('.masthead2').css('background-image', 'url("../img/whitehead ...

Having trouble making alerts or confirmation dialogs function in JavaScript

EDIT: Many thanks to everyone who helped fix this issue (: Your help is greatly appreciated! I've been struggling to get the alert, confirm, or prompt functions to work properly in my code. Here's a snippet of the code that's causing troubl ...

PHP, HTML, Email - Special characters in emails are being altered into other symbols

Here's the Situation... I am currently utilizing PHP to send out emails in a conventional manner... Snippet 0 mail('', $subject, $message, $headers); ... with the following content setup: Snippet 1 $boundary = uniqid('np&a ...

HTML5 Positioning Timeout

While working on my project, I incorporated the HTML Geolocation feature. However, I have observed that it is not always dependable. I am looking for a solution to add a backup plan that will time out after x seconds and display an error message. Any sugg ...

Design the title attribute for the style area tag

Currently, I have set up an image with various clickable areas on it, and I want to display a description when the user hovers over these areas. My current solution involves adding the descriptions as titles, but I feel like there might be a better way to ...

clicking the anchor will toggle the div

Here is the HTML code that I am working with: <? while($arr as $data) { ?> <td> <div> <a href="javascript:void(0)" class="status <?= $data['SUGGESTION_CD'] ?>"> <img src="images/activate.gif" /> &l ...

Looking for a solution to a problem with your vertical CSS/jQuery dropdown menu

My web app features a vertical CSS menu that is working correctly except for one minor issue. When I mouse out on all elements with the class a.menutoggle, the last dropdown menu remains open. I am struggling to find a solution to hide it. Can someone plea ...

Adjusting height dynamically with CSS based on font size

Below is a link followed by a span element <a href="#" style="display:inline-block;font-size:900%">12</a> <span display="block">ACTIVE</span> The issue arises when the 'a' element does not have a specific height, causing ...

Incorporating Microsoft's Emotion API into an HTML website

Currently, I am attempting to develop a HTML webpage that can detect emotions from images submitted by the user. By referring to Microsoft's documentation, I have produced the following HTML file: <!DOCTYPE html> <html> <head> & ...

Visual feedback: screen flashes upon clicking to add a class with jQuery

I have successfully added a click event to my pricing tables in order to apply an animation class on mobile devices. However, I am facing an issue where every time I click on a pricing option on my iPhone, the screen flashes before the class is applied. Is ...

What is the best way to save geolocation coordinates in a Javascript array?

I am attempting to utilize HTML5 geolocation to determine a user's location and then store the latitude and longitude coordinates in an array for future use with Google Maps and SQL statements. However, when I attempt to add these coordinates to the a ...