I am experiencing difficulty with the color of my progress bar in Firefox

After successfully creating an interactive progress bar that works perfectly in Google Chrome and surprisingly also in Safari without vendor prefixes, I encountered a roadblock when testing it on Firefox. The progress bar color reverts back to the default blue in Firefox despite my efforts to fix it using vendor prefixes. Now, I'm in a bit of a dilemma about which approach to take next. I've heard about feature queries but never used them before, so I'm unsure if this situation calls for their use or not. Ideally, the progress bar should be red until it reaches 100% and then change to green. Below is the current code snippet:

(function() {
  var button, heading, initialValue, progressbar;

  button = document.getElementById('btn');

  progressbar = document.getElementById('progress-bar');

  heading = document.getElementById('visual-progress');

  initialValue = 'Quiz Progress';

  button.addEventListener('click', function() {
    var myValue;
    if (progressbar.value >= 100) {
      progressbar.value = 100;
    } else {
      progressbar.value += 25;
    }
    if (progressbar.value === 100) {
      progressbar.classList.add('progress-100');
    }
    myValue = initialValue + ' ' + progressbar.value;
    document.getElementById('visual-progress').innerHTML = myValue + '%';
    return button.classList.add('button-active');
  });

}).call(this);
@import url("https://fonts.googleapis.com/css?family=Playfair+Display");
nav {
  background: black;
  height: 80px;
  width: 100%;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 10px;
}

.progress-container {
  padding: 10px 20px;
  margin-top: 3em;
}

progress {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  width: 100%;
  height: 20px;
}

progress::-webkit-progress-bar {
  background-color: #ccc;
  width: 100%;
}

progress::-moz-progress-bar {
  background-color: #ccc;
  width: 100%;
}

progress::-webkit-progress-value {
  background-color: #D22128 !important;
  -webkit-transition: all .7s;
  transition: all .7s;
}

progress::-moz-progress-value {
  background-color: #D22128 !important;
  -webkit-transition: all .7s;
  transition: all .7s;
}

.progress-100::-webkit-progress-value {
  background-color: forestgreen !important;
  -webkit-transition: all .5s;
  transition: all .5s;
}

.progress-100::-moz-progress-value {
  background-color: forestgreen !important;
  -webkit-transition: all .5s;
  transition: all .5s;
}

button {
  margin-top: 2em;
  background: transparent;
  color: black;
  border: 1px solid black;
  padding: .7em 3em;
}

.button-active {
  -webkit-transition: all .2s;
  transition: all .2s;
  background: black;
  color: white;
}

.card-container {
  max-width: 450px;
  margin: 0 auto;
}

.success-message {
  font-family: 'Playfair Display', serif;
  text-align: center;
  padding-bottom: 2em;
  -webkit-animation: slideUp .5s;
          animation: slideUp .5s;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3), 0 6px 13px rgba(0, 0, 0, 0.22);
  padding: 20px;
  margin-top: 3em;
  min-height: 150px;
}

.success-paragraph {
  font-size: 14px;
}

@-webkit-keyframes slideUp {
  from {
    -webkit-transform: translateY(500px);
            transform: translateY(500px);
  }
  to {
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    -webkit-transform: translateY(500px);
            transform: translateY(500px);
  }
  to {
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
}
<body>
  <nav></nav>
  <div class='container'>
    <div class='progress-container'>
      <h1 class='ut-margin-v-sm' id='visual-progress'>Quiz Progress</h1>
      <progress id='progress-bar' max='100' value='0'></progress>
      <button id='btn'>Next</button>
    </div>
  </div>
  <div class='card-container'>
    <div id='output'></div>
  </div>
</body>

Answer №1

It appears that Firefox does not support the ::progress-value pseudo-element.

To address this in Firefox, you will need to target the parent ::progress-bar.

(function() {
  var button, heading, initialValue, progressbar;

  button = document.getElementById('btn');

  progressbar = document.getElementById('progress-bar');

  heading = document.getElementById('visual-progress');

  initialValue = 'Quiz Progress';

  button.addEventListener('click', function() {
    var myValue;
    if (progressbar.value >= 100) {
      progressbar.value = 100;
    } else {
      progressbar.value += 25;
    }
    if (progressbar.value === 100) {
      progressbar.classList.add('progress-100');
    }
    myValue = initialValue + ' ' + progressbar.value;
    document.getElementById('visual-progress').innerHTML = myValue + '%';
    return button.classList.add('button-active');
  });

}).call(this);
@import url("https://fonts.googleapis.com/css?family=Playfair+Display");
nav {
  background: black;
  height: 80px;
  width: 100%;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 10px;
}

.progress-container {
  padding: 10px 20px;
  margin-top: 3em;
}

progress {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  width: 100%;
  height: 20px;
}

progress::-webkit-progress-bar {
  background-color: #ccc;
  width: 100%;
}
/* Targeting the element directly for Firefox */
progress{
  background-color: #ccc;
  width: 100%;
}

progress::-webkit-progress-value {
  background-color: #D22128 !important;
  -webkit-transition: all .7s;
  transition: all .7s;
}

progress::-moz-progress-bar { /* Adjusting for Mozilla Firefox */
  background-color: #D22128 !important;
  transition: all .7s;
}

.progress-100::-webkit-progress-value {
  background-color: forestgreen !important;
  -webkit-transition: all .5s;
  transition: all .5s;
}

.progress-100::-moz-progress-bar {
  background-color: forestgreen !important;
  transition: all .5s;
}

button {
  margin-top: 2em;
  background: transparent;
  color: black;
  border: 1px solid black;
  padding: .7em 3em;
}

.button-active {
  -webkit-transition: all .2s;
  transition: all .2s;
  background: black;
  color: white;
}

.card-container {
  max-width: 450px;
  margin: 0 auto;
}

.success-message {
  font-family: 'Playfair Display', serif;
  text-align: center;
  padding-bottom: 2em;
  -webkit-animation: slideUp .5s;
          animation: slideUp .5s;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3), 0 6px 13px rgba(0, 0, 0, 0.22);
  padding: 20px;
  margin-top: 3em;
  min-height: 150px;
}

.success-paragraph {
  font-size: 14px;
}

@-webkit-keyframes slideUp {
  from {
    -webkit-transform: translateY(500px);
            transform: translateY(500px);
  }
  to {
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    -webkit-transform: translateY(500px);
            transform: translateY(500px);
  }
  to {
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
}
<body>
  <nav></nav>
  <div class='container'>
    <div class='progress-container'>
      <h1 class='ut-margin-v-sm' id='visual-progress'>Quiz Progress</h1>
      <progress id='progress-bar' max='100' value='0'></progress>
      <button id='btn'>Next</button>
    </div>
  </div>
  <div class='card-container'>
    <div id='output'></div>
  </div>
</body>

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

Is there a way to use Css Autoprefixer on multiple files at once with a single function

My project built with Angular2 contains over 100 CSS files that do not have any prefixes for browsers like Mozilla or Chrome. I am looking for a tool, gulp task, or anything else that can automatically add prefixes to all of my CSS files. I attempted to u ...

Looking to verify the existence of a div using jQuery once other jQuery functions have executed and created HTML?

Is there a way to verify if a specific element exists within newly added HTML after clicking a button? I attempted this code snippet: $(document).on('click', '#add-html-code', function() { if ($('#something').length ...

Issue with Angular 5 - Deselect all checkboxes not reflecting in the UI

I am currently working on integrating a reset button into a Reactive form in Angular 5. The reset functionality works flawlessly for all form fields, except for the dynamically created multiple checkboxes. Although it seems like the reset operation is hap ...

The presence of an unauthorized token within the meteor/node module has been detected, specifically related

While following g00glen00b's tutorial on meteor/twitter integration (), I encountered a persistent error. Any assistance or clues would be greatly appreciated. Steps I've Taken Uninstall/reinstall npm Uninstall/reinstall twitter package Uninst ...

What could be the reason for the absence of the CSS destination folder being generated by

My colleague has the exact same code and can run gulp without any issues, but I'm struggling to compile the css files using Gulp. Gulp isn't creating the css destination file or the css files themselves. However, it works perfectly fine for build ...

What is the best way to connect my data with my Backbone Views?

I have successfully set up my views to show test data, and now I want to implement asynchronous data loading to fetch real information. However, I'm a bit confused on the best method to achieve this. Should I manually create AJAX calls? Or maybe utili ...

Using jQuery to toggle CSS properties

I'm having trouble switching between a CSS column layout and a normal layout for a div element with the ID 'article'. The jQuery script I wrote doesn't seem to work properly, as the entire thing disappears. Can anyone advise me on how t ...

Using AngularJS to update text content retrieved from a file and display it in a textarea

Is there a way to create a textarea using AngularJS that can be populated either by typing, entering a URL, or uploading a plain text file? While I am able to load the file content into the variable linked to the textarea, I'm facing an issue where ge ...

Spin a three-dimensional cube on a platform using three.js with a unique functionality

I am attempting to create an animation featuring a cube on a flat surface. The cube can be rotated along the x/y axis only, with no need to show its underside. I want to be able to tip the cube over any edge - when a side of the cube touches the surface, i ...

The MIME type 'text/html' is incompatible with stylesheet MIME type and is not supported

I have exhausted all possible solutions for the issue, from specifying the type for <link rel="stylesheet" href="./style.css" /> to using app.use(express.static('public')), but unfortunately, none of them seem to resolve the problem. index ...

How to send the file path to an API in JavaScript to convert it

I am currently working on a web application that allows users to upload a wav file and convert it to mp3 format. I have successfully implemented the wav to mp3 conversion and saving it to the project folder. However, I am facing an issue with dynamically p ...

What effect does setting div1 to float left have on the layout of div2 in css?

Behold the mystical code written in HTML. <div id="sidebar1"> sidebar1 </div> <div id="sidebar2"> sidebar2 </div> Beneath lies the enchanting CSS code for the aforementioned HTML structure. div { width: 100px; ...

`When you extend a $resource object, it effectively removes the prototype from the

Here's the current code snippet I'm working with: // Factory angular.factory('Student', function() { var defaults = { StudentId: null }; var Student = function(params) { angular.extend(this, angular.copy(de ...

Utilize HTML5 localStorage functionality

I have a good understanding of utilizing HTML5 localStorage with methods like localStorage.getItem/setItem. However, I am currently trying to figure out the implementation for a dynamic page. Let me explain the scenario: On my dynamic page (myPage.jsp), ...

Position the spinner in the center of the user's screen

I created my own spinner: '''' #spinner-bg-loading{ position: absolute; left: 50%; top: 25%; width: 80px; height: 80px; margin: -75px 0 0 -75px; border: 16px solid #FFFFFF; border-radius: 50%; border-top: 16px solid #1 ...

Exploring the World of Unit Testing with Jasmine and Sinon Factories

At my factory, I have implemented a getter and setter function .factory('myService', function() { var car = null; return { car: car, get: function get() { return car; }, set: function set(newCar) { car = newCar; ...

Can one open a unique custom pop-up before the window is about to close?

Seeking a way to create a pop-up confirmation dialog for users when they try to log out or stay on the page while logged in. I attempted using the code below, but haven't been able to find the correct solution: window.onbeforeunload = function (e) { ...

Encountering Empty Output When Trying to Save HTML Form Data to Database

I have recently started learning PHP and web development, and I am attempting to build an HTML form that will submit data to MYSQL. After submitting the form and checking phpMyAdmin, it shows that a row has been submitted, but the row is empty. Previously ...

I am facing an issue with effectively passing properties from a parent state to its child component

In the Login component, I set the authentication state using the token as false initially. After a successful login, the token is changed to true. function Login() { const [user, setUser] = useState({ name: '', email: '' }); const [ ...

Tips for avoiding repeated Modal Popup instances and preventing the page from automatically scrolling to the last element when using ReactJS

I've been working on a project where I'm fetching data from a server and displaying 10 different sets of data in Bootstrap cards using the map() function. Each card contains a button to open a modal, along with a Link that shows the route related ...