The issue with Bootstrap 4 fixed-top not functioning properly on mobile devices

An issue has arisen while using 'fixed-top' with Bootstrap 4. This feature works perfectly fine on the desktop for my nav bar, but when the navbar is collapsed, it fails to fix itself at the absolute top. Instead, when scrolling in the collapsed state, about 50% of the navbar disappears before becoming fixed at the top. However, upon scrolling back up, the navbar reappears. Here's a link to a short video demonstration: Video Link

<div>
<nav id="mainNav" change-class class="navbar fixed-top navbar-expand-lg navbar-transparent">

<!-- Logo -->
<a class="navbar-brand text-white" href="#"><span class="logo-script">Some</span><span class="logo-block">Brand</span></a>

<!-- Toggler -->
...

In addition to this, I am utilizing AngularJS to add color changes on scroll, although this seems unrelated as it functions well on larger screens but truncates the fixed-top position on smaller ones.

Your feedback and insights are greatly appreciated.

UPDATE: After further investigation, it appears that a specific code block related to the header may be contributing to this issue. Here is the troublesome code snippet:

<div class="header">
...

.header {
background: #7F00FF;
height: 100vh;

}

The behavior observed suggests that the navbar loads first followed by the header section. Removing the header reduces the extent of the issue significantly.

Answer №1

Upon running some tests using your provided code, I discovered that there was an issue with the HTML snippet you shared.

It is possible that this error was causing the problem you observed in your video because once I corrected it, I extensively tested the code and did not encounter any of the issues displayed in your demonstration. Additionally, I switched to using a Galaxy S5 (similar to your device in the video) and still did not experience any of the problems shown.

Below is the valid and functional code I utilized (click the "run code snippet" button below and expand to full screen for testing):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<nav id="mainNav" change-class class="navbar fixed-top navbar-expand-lg navbar-transparent bg-primary">

    <!-- Logo -->
    <a class="navbar-brand text-white" href="#"><span class="logo-script">Some</span><span class="logo-block">Brand</span></a>

    <!-- Toggler -->
    <button class="navbar-dark navbar-toggler" type="button" data-toggle="collapse" data-target="#navToggle" aria-controls="navToggle" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
    </button>

    <!-- Links -->
    <div class="collapse navbar-collapse" id="navToggle">
        <ul class="navbar-nav ml-auto">

            <li class="nav-item">
                <a class="nav-link text-white navbar-link-custom" href="#!/view1">SIGN IN</a>
            </li>

            <li class="nav-item">
                <a class="nav-link text-white navbar-link-custom" href="#">REGISTER</a>
            </li>

            <!-- Logged In Links -->
            <div class="dropdown">
                <a href="" class="nav-link text-white navbar-link-custom dropdown-toggle" type="text" id="profileDrop" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                WELCOME CHRIS
            </a>
                <div class="dropdown-menu dropdown-menu-right" style="padding-left: 2px; padding-right: 2px" aria-labelledby="profieDrop">
                    <button class="dropdown-item-custom navbar-link-custom" type="button">My Profile</button>
                    <div class="dropdown-divider"></div>
                    <button class="dropdown-item-custom navbar-link-custom" type="button">Logout</button>
                </div>
            </div>

        </ul>
    </div>
</nav>

<div class="container" style="margin-top: 90px;">
    <div class="row">
        <div class="col">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
            <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit.
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

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

Mirror Image Iframes

Currently, I have been tasked with constructing a side-by-side "frame" using HTML. The idea is that when the content in the iframe on the left is selected, it will appear in the iframe next to it on the same page. Here's some additional context: The ...

Utilizing React State to dynamically alter the look of a circle element upon clicking a button component

I'm having trouble adjusting the style of a circle component when it's selected by a button in another component. Both components need to change appearance upon selection, but I am facing issues with state management and feeling a bit overwhelmed ...

Is it possible to exclusively target a child div using JavaScript in CSS, without affecting the parent div?

I'm in the process of developing a calendar feature where users can select a specific "day" element to access a dropdown menu for time selection. The functionality is working fine, but I've encountered an issue. When a user selects a time from th ...

Different Types of Web Navigation Menus and Common Implementation Strategies

Are there recognized Navigation Menu designs for creating interactive navigation menus with dropdown panels on a Website? For instance, when you click on the StackExchange link at the top left, a panel with content appears, and when you click on your User ...

Establish a timeout period for ajax requests using jQuery

$.ajax({ url: "test.html", error: function(){ //do something }, success: function(){ //do something } }); At times, the success function performs well, but sometimes it does not. How can I add a timeout to this ajax re ...

Include a div with absolute positioning that fits within the visible browser window

My current project involves creating a graphical canvas map with tooltips, but I am facing a challenge. I need to ensure that the tooltips, which are absolute positioned divs, remain within the viewport. Unfortunately, I am having trouble achieving this. ...

What is the best way to showcase my background image using html and css?

I've come across a similar topic addressing my problem, but I am still unable to resolve it. I am attempting to add a background image to my portfolio, but for some reason, it is not working. Can anyone offer any suggestions or ideas? Here is the cod ...

Header on top of table that stays in place with scrolling

I'm facing an issue with a table that contains user-generated data. We are utilizing a plugin known as Clusterize, which allows us to smoothly scroll through large amounts of rows. However, the specific markup required for this plugin seems to be caus ...

Issues arise when trying to integrate iframes with Ionic and AngularJS, as they

Using iframes in my ionic app to display webpages within the application has presented a challenge. This is what I currently have implemented: <iframe class= 'webPage' name= "eventsPage" ng-src="{{object.url}}"></iframe> The issue ...

Ensure that the inner div has a height of 100%

Can someone help me troubleshoot my HTML code? <div id="container"> <div id="left-container"> </div> <div id="right-container"> </div> </div> Although the container is set to 100% height, the #left_con ...

Increase the border thickness on the top side of the div

To enhance the design of the .menu div, I decided to include an additional border at the top. Initially, I incorporated top and bottom borders using box-shadow, followed by traditional borders using border-bottom, border-left, and border-right properties. ...

The linear transition property in CSS is not being followed as expected

I'm trying to create a smooth linear transition on the height of a box with CSS, but it's not working as expected. Currently, the transition is abrupt - the height suddenly increases and then the margins take up all the time. Can someone provide ...

My website appears distorted when the browser is zoomed out. What could be causing this issue?

Whenever I try to zoom out using Internet Explorer, the page doesn't zoom uniformly and ends up looking messy. Can someone please help me understand why this is happening? Here's how the page looks after zooming out (take a look at the three box ...

Combining D3.js tooltip positioning with CSS overflow styling

I am encountering an issue with displaying tooltips in D3 when combined with CSS overflow. Is there a solution available for this particular problem? CSS code: #chart1 { overflow-x: auto; overflow-y: hidden; max-width: 800px; max-height: 22 ...

Create buttons to increase or decrease values using Bootstrap and JavaScript

What is the proper way to make this button function properly? I tested adding this line of javascript code, however it prompts an alert without clicking on the buttons as well. document.querySelector(".btnminus").addEventListener(onclick,ale ...

What methods can I utilize to transmit Global variable data from a view to a controller?

In my Angular view file, I have the following code snippet. <!DOCTYPE html> <video id="myVideo" class="video-js vjs-default-skin"></video> <script> var dataUri; var videoData; var player = videojs("myVideo", { controls ...

Troubleshooting: Android compatibility issues with dynamic source for HTML 5 video

My HTML5 video with dynamic source loaded using JavaScript is functioning properly in a web browser but encountering issues within an Android PhoneGap build application. Take a look at the code snippet below: JavaScript code: $('#video_player' ...

Adding a component dynamically with a link click in Angular: A step-by-step guide

I am encountering an issue with my web application setup. I have a navigation bar, a home page with left and right divs, and a view-associates component. My goal is to dynamically add the view-associates component into the home's right div when a spec ...

Effortlessly uploading multiple files using Multer

Having trouble uploading multiple images using Multer? While everything seems to be in place, only the last file selected gets uploaded. Here is the HTML: <form class='new-project' action='/projects' method='POST' enctype ...

Tips for implementing cellRenderer in ag-grid table using React JS

Using the react js ag-grid method, I created a table and then passed my json data into the React table. The json file data is as follows: { "posts": [{ "cam1": "3 persons, 1 car, 1 bottle, 2 chairs, 1 tv", "cam ...