The CSS option style is not functioning properly in Firefox

I'm having trouble getting my custom styles for an option select box to work in Mozilla Firefox using CSS.

While everything looks fine in Google Chrome, the styles are not rendering correctly in Firefox. What am I missing in my CSS code to make it compatible with Firefox as well?

If anyone has any insights or solutions, I would greatly appreciate the help!

.container {
   position:relative;
   width:100%;
   max-width:500px;
   margin:0px auto;
   margin-top:100px;
   padding:40px;
   background-color:#fafafa;
   border:1px solid #d8dbdf;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    ...
      </select>
   </div> 
</div>

Answer №1

According to my observation: <select> elements can be quite tricky to style, mainly because of the OS- and vendor-specific styles that can interfere with customization. The most effective approach is to completely reset the element by utilizing the appearance property set to none, and then substituting a background image for the dropdown arrow.

Another issue in your styling is that you have defined a padding of 18px on the select element, while its height is only 30px. This results in the content having no space (in fact, -6px) to display properly. To resolve this, reduce the vertical padding to a lower value so that the text displays correctly, for example, I used padding: 4px 18px.

In the sample below, I incorporated a dropdown arrow from Google Material Icon's collection converted into base64 code. Any SVG can easily be transformed into base64 using this platform.

.container {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0px auto;
  margin-top: 100px;
  padding: 40px;
  background-color: #fafafa;
  border: 1px solid #d8dbdf;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: stretch;
  -webkit-align-items: stretch;
  -ms-flex-align: stretch;
  align-items: stretch;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

.i_bd select {
  background-color: rgb(255, 255, 255, 1) !important;
  border-radius: 3px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;

  /* Make sure to decrease top/bottom padding! */
  padding: 4px 18px;
  color: #333333;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  border: 1px solid rgba(239, 239, 239, 1);
  width: 80px;
  height: 30px;
  
  /* Remove vendor-specific appearance */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  
  /* Utilize triangle background as arrow */
  background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gICAgPHBhdGggZD0iTTcgMTBsNSA1IDUtNXoiLz48L3N2Zz4=);
  background-size: 24px 24px;
  background-repeat: no-repeat;
  background-position: center right;
}

.i_bd {
  -webkit-box-flex: 1;
  -webkit-flex-grow: 1;
  -ms-flex-positive: 1;
  flex-grow: 1;
  -webkit-flex-shrink: 1;
  -ms-flex-negative: 1;
  flex-shrink: 1;
  position: relative;
  float: left;
  margin-right: 10px;
}
<div class="container">
  <div class="i_bd">
    <select name="select">
         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
      </select>
  </div>
</div>

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 retrieve the text of li elements without assigning them IDs?

I have a list of names with four items inside it. My goal is to display the text of the selected name while hiding the others. Only one name should be visible at a time on the page. <ul id="names"> <li>John</li> <li>Alex</ ...

Enabling and disabling multiple input fields based on the status of a checkbox in order to manage dynamic inputs

I need help with a situation involving dynamic input fields and checkboxes. My goal is to disable the input field if the checkbox with the corresponding ID is checked. Here is the PHP code snippet: <table class="table table-striped"> <thead& ...

What is the best way to display a success notification when a transaction is successfully executed in web SQL

var brand = "Glare"; var price = "3000$"; var color = "blue"; var success = tx.executeSql("INSERT INTO truck (brand, price, color) VALUES ('"+brand+"','"+price+"','"+color+"' ")"); if(success) { alert("successfully insert ...

Ways to add a CSS class to an ID that immediately follows

I've been working on an editable table using the HTML5 attribute contenteditable. Everything was going smoothly until I had an idea to highlight the cell that was just updated by adding a class called alert-danger from Bootstrap. Once a cell is succe ...

Creating three boxes within a single div using standard HTML and CSS

I created this design using Microsoft Paint and now I want to bring it to life using HTML and CSS. https://i.stack.imgur.com/dwNZi.png The numbers represent the box numbers in the design. Here is my attempt at coding this: HTML file <!DOCTYPE html& ...

Include the window.innerWidth value in the initial GET request

When dealing with a server-side rendered app that has responsive styling based on window.innerWidth, the challenge lies in how to pass the client's screen size in the initial GET request for index.html. This is crucial so that the server can prepare a ...

What steps can I take to repair broken links in a Bootstrap template?

I am currently working with the startbootstrap-bare template from Blackrock Digital. My goal is to have different content load when a user clicks on the About link (about.html), while still keeping the navigation menu intact. However, when I change the hr ...

arranging rows and columns in bootstrap version 4.1

Currently, I have a structure with rows and columns that I need to rearrange for mobile responsiveness. The main row consists of three columns, each containing rows in a vertical layout. Here is an example: https://i.sstatic.net/tFEhs.png For mobile view ...

PHP and Ajax Form Submission Directing to Backend PHP Script

While working on a portfolio, I encountered an issue with the contact form. When I click the submit button to send a message, instead of displaying the bootstrap alert message below the form, the page redirects to the PHP file. Although I receive the emai ...

Creating columns of equal height using Bootstrap 3 and flexbox

Working with Bootstrap 3 (unable to switch to Bootstrap 4) and looking to achieve the same-height columns effect as shown in the image: https://i.sstatic.net/WR55a.jpg Managed to get it done using position absolute and @media screen for image size and padd ...

Issue with customizing CSS in Fullcalendar Version 5 for Angular not functioning as expected

Currently, I am integrating Fullcalendar v5 into our Angular project and am looking to customize the Fullcalendar toolbar title color and size. In the styles.scss file, I inserted the following CSS code: .fc .fc-toolbar-title { font-size: 1.2em; color ...

Easily collect form information from an HTML <form> element

I've been struggling to figure out how to retrieve data from an HTML form and display it in the console. What step am I overlooking? Here is the HTML code I'm working with: <!DOCTYPE html> <html> <head> <title>U ...

What is the best way to activate Bootstrap's tooltip functionality following its inclusion via AJAX?

One of the features I am adding to my website using ajax is a tooltip. The snippet looks like this: <a href="#" data-toggle="tooltip" title data-original-title="My tooltip text...">Hover me...</a> To get it to work, I need to initialize it as ...

Using HTML to place an image tag close to an input element

I'm experiencing a strange issue where adding an img tag alongside an input and a span causes the input and span to shift downwards. <div> <span>Credit Points</span> <input type="text" name="credit_points" value="2.25"/> ...

Leverage Bootstrap 4 for achieving flexible layouts and centering content with two elements using flex and justify-content

By using the d-flex, justify-content-center, and flex-grow-1 classes, I was able to achieve my desired layout with just 3 divs. <div class="row bg-primary d-flex justify-content-center"> <div class="col-auto"> LEFT </div> < ...

How can I switch the default browser in the most recent version of visual studio code?

Question: The default browser is IE, but I am looking to switch to a different browser. How can I make this change? ...

Problem with Flexbox Wrapping on iPhone 6

I love the flexibility that flexbox provides, but I've been facing an issue specifically with wrapping on iOS devices. Is there a simple fallback option for handling wrapping? Here's a problem scenario where items refuse to wrap: ( JSFiddle Fans ...

Creating responsive layouts with flexible image sizes using Flexbox

My exploration of Flexbox began by testing it on an existing template sourced from a previous stackoverflow question. I am currently focusing on adjusting the image size to better fit within its parent div. max-width: 50px; height: auto; margin:auto; ...

What is the best way to handle JSON data in JQuery when it is returned with a header type of "text/html"?

I'm attempting to utilize the jquery getJSON method in order to retrieve JSON data from a public API. However, I am consistently encountering errors when the callback of my getJSON request is executed. Warning: Resource interpreted as Script but trans ...

Using CSS transition on the height property does not produce the desired effect

I'm currently working on a menu interaction that activates on click. Here is the code snippet for reference: let btn = document.querySelector('.trigger'); let icons = document.querySelector('.icons'); let labels = document.query ...