Differences between Firefox and Webkit browsers when it comes to scrolling - How side navigation, text truncation, and

Scrollbar appearance is causing an issue across different browsers. The truncated text in my side-navigation component is not displaying correctly on Firefox and IE browsers.

View this fiddle on both Chrome and Firefox:

https://jsfiddle.net/d84b9m49/10/

Upon inspection, the scrollbar positioning is different in Webkit as opposed to Firefox/IE. In Firefox, the scrollbar appears within the right padding area of 65px (as specified in the style), while Chrome displays it outside the padding area, totaling 85px (65px + scrollbar width). In Firefox, when the scrollbar appears, the content inside the li items is off-center with some text partially hidden below the scrollbar (triggering a horizontal scrollbar) whereas in Chrome, everything remains centered. Refer to the documentation for more details about this scrollbar handling difference (ISSUE 1):

https://drafts.csswg.org/css-overflow-3/#scrollable

A prior solution was applying max-width: 65px (refer to this fiddle) but this approach is not ideal when dealing with short text that may cause the navigation's width to fluctuate undesirably.

Ensure the navigation component layout is maintained on smaller devices under 768px (in the example provided, it switches to "bottom" navigation).

The goal is to have the items in the navigation centered on both Chrome and Firefox, disregarding IE for now.

If anyone could provide assistance with this issue, any help would be greatly appreciated.

EDIT: For future reference, refer to the upvoted answers below based on your specific needs (either adopt the scroll check method or opt to remove scrollbars while adding scrolling arrows).

Answer №1

To hide the scrollbar directly from my comment, you can use the following CSS:

::-webkit-scrollbar { display: none;}

Alternatively, you can calculate the width of the scrollbar using jQuery and add the same margin to the body/container.

You can try coding something like this:

var checkScrollBars = function(){
    var normalwidth = 0;
    var scrollwidth = 0;
    if($('body').prop('scrollHeight')>$('body').height()){
        normalwidth = window.innerWidth;
        scrollwidth = normalwidth - $('body').width();
        $('#container').css({marginRight:'-'+scrollwidth+'px'});
    }
}

For horizontal scrollbar only:

body{
overflow-x:hidden;
}

EDIT

As per your comment, if you are concerned about performance overhead, you can calculate the scrollbar width only once and add it by default on page load.

You can do it this way:

function scrollbarWidth() { 
    var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>'); 
    // Append our div, do our calculation and then remove it 
    $('body').append(div); 
    var w1 = $('div', div).innerWidth(); 
    div.css('overflow-y', 'scroll'); 
    var w2 = $('div', div).innerWidth(); 
    $(div).remove(); 
    return (w1 - w2); 
}

Or call these functions (above two) only if the inner width is less than some <80px like this:

if ($(window).width() < 85px) {
   //your function
}

Answer №2

To eliminate the scrollbar, use the following CSS code:

.nav.navbar.navbar-inverse::-webkit-scrollbar { width: 0 !important }
.nav.navbar.navbar-inverse { -ms-overflow-style: none; }
.nav.navbar.navbar-inverse { overflow: -moz-scrollbars-none; }

View it in action on jsFiddle

Answer №3

There seems to be a problem with the scroll bar in Firefox, but it can easily be fixed by adding some CSS code. Simply include padding-right: 18px (which is the width of the scroll bar) to the element with overflow-y property. Here's an example:

.navbar {
    padding: 0;
    background: #283030;
    height: 100%;
    overflow-y: auto;
    padding-right: 18px;
}
li.nav-item {
    width: 65px;
}

By setting the width to 65px, the issue should be resolved.

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

Spontaneous Lettering using HTML Tags

Have you ever tried using a random letter as an HTML tag? I was experimenting with it and found that even though 'f' isn't a standard tag, it functions similarly to a span tag in some cases. I know this may be a silly question, but I've ...

Hovering into Transition Time

My article card has a transition on the top attribute of the info div, which is supposed to be smooth and last for 0.3 seconds. However, the description suddenly appears during this transition. I'm trying to figure out why this is happening and how to ...

What is causing the clickAt function to fail in Selenium IDE?

It seems that Selenium IDE has some unreliability issues. For instance, the last command in the script below does not work within the script itself, yet it opens the file selection dialog when double-clicked separately. Why is that? Another question I hav ...

Is it possible to obtain the index of a table row using querySelector?

Is it possible to find the rowIndex of the first occurrence of a table row within the #myTable using JavaScript? http://jsfiddle.net/bobbyrne01/fmj6np6m/1/ html .. <table id="otherTable"></table> <table id="myTable"></table> js ...

Difficulty with linking a CSS property to an HTML element using JavaScript

I'm currently working on building a custom carousel from scratch. Instead of using pre-made code snippets, I decided to challenge myself by creating one using setTimeout in JavaScript. However, I seem to be encountering an issue that I can't quit ...

What is the best method for creating a fade effect on a div background?

I am trying to animate a div with the id #test from a 0 opacity background to an opacity of 0.7 using CSS rgba values, but for some reason, the .animate function is not working as expected. Here is my CSS: #test { background-color: rgba(0, 0, 0, 0); ...

Can you tell me what is creating the space between the elements in this form?

For an example, take a look at this link: I am puzzled by the gap between the form-group and the button, as well as between the different form-groups. When using Bootstrap 4 with flexbox activated, all my elements (inputs and buttons) collapse without any ...

Responsive design of HTML forms

I'm curious about the technology or concept behind Google's animations on their forms. I'm interested in incorporating it into my personal project. The use of radio buttons, checkboxes, and placeholders is particularly appealing. Is there ...

Using React to wrap a cards-deck inside a cards component with plain bootstrap styling

Hello everyone, I'm currently working on creating a deck of cards using plain Bootstrap. In my main file, I have set up the deck as follows: <div className="container"> <div className="card-deck"> <MyCard /> & ...

What is the best way to manage selected checkboxes in PHP?

Could you please assist me with a problem I am facing? I have a form where users can select checkboxes, but I'm struggling to display the selected checkbox item names in the result. Currently, my HTML site is using the value attribute to calculate the ...

What possible reason could there be for the empty space on the left side?

<ul style="background: blue; list-style: none; width: 40px; height: 40px; color: white"> <li style="float: left; width: 20px; background: red">a</li> <li style="float: left; width: 20px; background: green; height: 40px">b</li ...

How to achieve a text border effect using inner glow technique

Can someone help me recreate this unique text design? The font used is Gill Sans MT and the text color is a shade of purple although it may be hard to discern. https://i.sstatic.net/HGrB8.png I have been struggling to achieve the vibrant thick border and ...

Enhancing Twitter Bootstrap with custom media queries for an extra-small breakpoint

It came as a surprise to me that Twitter Bootstrap does not include media queries specifically for creating a well-suited version of a website for mobile portrait screens. Defining the width for "mobile portrait" is a bit complicated. In the past, most ph ...

How can I incorporate a personalized SVG path to serve as a cursor on a webpage?

Is there a way to enhance the functionality of binding the 'mousemove' event to a div and moving it around the page while hiding the real cursor? Specifically, can we change the shape of the circle to an SVG path and drag the SVG path around the ...

What is the best way to use border radius on a canvas element similar to a div in order to create a

I'm having trouble making a canvas element appear as a circle like any other div. Here is my code, please take a look and let me know what I'm doing wrong with the border-radius property: <canvas id="myCanvas" width="200" height="200" style ...

The footer moves upwards when a file is downloaded

I am facing an issue with my website footer and its CSS styling. #footer { position: absolute; bottom: 0; width: 100%; height:8rem; } The main goal is to keep the footer at the bottom of the page, regardless of the amount of content on th ...

Load JavaScript files in order within the <body> tag and trigger a callback function when all files have

Currently, my website (which is actually a Cordova/Phonegap app) has the following scripts in the <head>: <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="appPolyfills.js"></script> ...

Using Jquery to encase an element in a div while scrolling down and removing it while scrolling up

After some experimentation, I've managed to wrap an element inside a div using jQuery. My next challenge is to wrap it as you scroll down and unwrap it as you scroll up. Do you think this is achievable? Although I have succeeded in wrapping it while ...

Exploring the concept of nested views in AngularJS's UI Router with multiple views integration

I am facing an issue with configuring multiple views on one page, where one view is nested within another. My code in app.js does not seem to be working properly. Below are the details: This is my index.html file <body ng-app="configuratorApp" > ...

Email confirmation section

I'm in the process of setting up a subscription newsletter page, and everything seems to be working correctly except for the part where I need users to enter their email address twice. The second email field is meant for confirmation purposes, but I&a ...