Changing the background color of a select box without removing the right arrow on Mobile Safari

I am trying to update the background color of my select box to a solid color while keeping the right arrow (drop-down arrow) visible.

My current approach is as follows:

select {
    -webkit-appearance: none;
    border: 0;
    background: none;
}

While this method works well in most browsers, Safari on my iPhone 4s with iOS 7 is an exception. In this case, the right-arrow disappears and may confuse users regarding the functionality of the select box.

Removing the -webkit-appearance property does not resolve the issue.

I want to avoid creating a fake arrow, as this could impact other browsers' appearances.

Any suggestions on how to retain the right arrow when changing the background color?

Answer №1

Here is the solution I found for iOS8 to eliminate the gradient and allow the dropdown to appear on a non-white background:

To achieve this, I applied background-color: white before adding the image.

I also included a custom arrow using a base64 PNG directly in my CSS.

.uglyselect & select  
{
    -webkit-appearance: none;
    background-color: white;
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAJCAYAAAA/33wPAAAAvklEQVQoFY2QMQqEMBBFv7ERa/EMXkGw11K8QbDXzuN4BHv7QO6ifUgj7v4UAdlVM8Uwf+b9YZJISnlqrfEUZVlinucnBGKaJgghbiHOyLyFKIoCbdvecpyReYvo/Ma2bajrGtbaC58kCdZ1RZ7nl/4/4d5EsO/7nzl7IUtodBexMMagaRrs+06JLMvcNWmaOv2W/C/TMAyD58dxROgSmvxFFMdxoOs6lliWBXEcuzokXRbRoJRyvqqqQvye+QDMDz1D6yuj9wAAAABJRU5ErkJggg==);
    background-position : right center;
    background-repeat: no-repeat;
    padding-right: 1.5em;
}

If you're wondering about .uglyselect, it's my Modernizr test specifically designed for iPad devices.

 Modernizr.addTest('uglyselect', function ()
 {
     return navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false;
 });

Feel free to rename or remove it if not using Modernizr. I chose to target iOS only to simplify testing since the default desktop dropdown style worked fine for me.

(Adjust padding values as needed, especially for longer text inputs).

Answer №2

When it comes to styling the select element using CSS, finding a reliable cross-browser implementation can be quite challenging. A more effective approach is to develop your own dropdown menu with JavaScript and apply consistent styles to ensure uniformity across all browsers.

Answer №3

This approach has proven to be effective for me personally.

If you are utilizing modernizr, include the following code in your scripts file:

jQuery(function ($) {
    if (navigator.userAgent.match('iPad|iPhone|iPod') != -1 ) {
        $('select').addClass('iOSselect'); // apply a class for iOS select box
    }
});

Afterwards, implement the specific CSS styles mentioned in other posts.

For instance:

select.iOSselect {
    -webkit-appearance: none;
    background-color: white;
    background-image: url('images/iOS-select-arrow');
    background-position : right center;
    background-repeat: no-repeat;
    padding-right: 1.5em;
}

I hope this information is helpful. There might be alternative methods, but this one has worked well for me.

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

"Difficulty encountered in getting scroll-x: auto to function properly in iOS and Safari when embedding an image with a click map inside a container

We're encountering an issue with a wide image (a colour palette) that is too large for mobile screens, so we decided to place the image in a container with a horizontal scroll bar. This solution works perfectly on most browsers, but not on iOS and Saf ...

The background image in CSS fails to display when a relative path is utilized

Currently, I am working on a JavaFX project which has the following file structure (CEP serves as the root directory): CEP +img menu.jpg +src +css_files MainMenu.css The main objective is to set the background image from the img dir ...

Should ng-binding be avoided in CSS selectors as a general rule?

Recently, I stumbled upon this code snippet in our codebase: li.ng-binding span { font-size: 13px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; } The selector above doesn't actually apply to one of the intended 'li& ...

JavaScript - Interactive sidebar that expands and collapses upon mouseover, maintaining its state when navigating between different pages

I am currently developing a multi-page web application using HTML, CSS, JavaScript, and jQuery. My focus is on creating a sidebar component that expands and collapses when the user hovers over it or moves the mouse out. This sidebar contains links to vario ...

Issues with Windows font rendering when using @font-face in CSS

Encountering issues with @font-face on Windows computers, regardless of the browser used. The fonts display properly on Linux and OSX. Below is the CSS code I'm currently using (generated with font-squirel) Review the screenshots for the identified ...

Replace Picture as you Scroll

Is it possible to swap images based on scroll position? For instance: When scrolling 100px, display img1.jpg When scrolling 200px, display img2.jpg When scrolling 300px, display img3.jpg Here's an example of what I'm looking for. Any suggest ...

A layout featuring three columns with two collapsible navigation menus on the left side

An Overview of My Current Project My ongoing project involves a webpage layout consisting of three columns arranged from left to right as follows: Project List Code Details Code Window The Project List and Code Details columns are set with a max-width ...

Clicking on the background does not alter the onclick function

Can anyone help me troubleshoot my code? My function load() isn't changing the background of .firstDiv for some reason. I've checked multiple times but I can't seem to spot any errors. function load() { document.getElementsBy ...

When enclosed within a class, the specification of CSS can be clearly defined

I am attempting to achieve the following in my Rails application: Let's suppose I have a class called .foo .foo{ color:red;} and another class named .bar .bar{ color:green;} I aim to change the color of the foo elements to blue, but only when the ...

Mysterious jQuery feature: Transform your top slider to slide in from the right side

My expertise lies in web design using Photoshop, while other programmers bring my designs to life. However, I've been considering taking on the coding part myself for a change with jQuery being outside of my comfort zone. This is my first project in w ...

Is there a way to modify the button's color upon clicking in a React application?

I am a beginner in the world of React and currently exploring how to utilize the useState hook to dynamically change the color of a button upon clicking. Can someone kindly guide me through the process? Below is my current code snippet: import { Button } ...

The safeAreaInsets property will return a value of 0 only for the iPhone 7 Plus and iPhone 8

When positioning a view relative to the bottom of the screen in my app delegate, I encountered an issue specifically on the iPhone 7 Plus and 8 Plus. The safeAreaInsets were reported as 0 on these devices, leading to incorrect positioning. Is there a reaso ...

Simple JavaScript File Loading without Rendering or Running Laravel 8 Bootstrap 5

Hey there, I just set up a fresh laravel and bootstrap project. All I've done so far is create a navigation bar. However, when I load the page, I noticed that the app.js file is loading but the CSS is not rendering properly because the app.css stylesh ...

Click outside to toggle dropdown and hide it

My dropdown menu is currently working, but I would like it to close when I click outside of it. I've tried various solutions provided in other posts, but I just can't seem to get it right. Can someone please help me figure out what I am missing? ...

Is Auto Layout limited to working with a specific screen?

So, I've been handed the task of updating an old iOS App. The UI is completely built using xib's or frames without any constraints. I have successfully rebuilt one screen with constraints, but unfortunately, the app still appears stretched on iP ...

Guidelines for creating a dynamic Bootstrap 4 accordion with Jquery

I need help adding a new Bootstrap 4 accordion when a button is clicked. Can someone assist me with implementing this feature in jQuery? I'm not sure if it's possible to add accordions dynamically using jQuery. <script> $(document).re ...

Issue with jQuery Cycle causing images not to load in IE all at once, leading to blinking

When using the jQuery Cycle plugin in IE8 (as well as other versions of Internet Explorer), I am encountering an issue. My slideshow consists of 3 slides, each containing a Title, Description, and Image. The problem arises when viewing the slideshow in I ...

Struggling to position an image and text side by side within a div using CSS

Is there a way to display a message inside a div with an icon positioned to the left? The desired outcome is for the icon to always be next to the text and aligned at the bottom-center of the div. https://i.sstatic.net/RnZMq.png https://i.sstatic.net/aSR ...

What is the best way to show a confirmation message in a pop-up after submitting a contact form?

I've been struggling to create a contact form that shows a thank you message upon submission, rather than redirecting to the contact.php file with no styling. You can see an example of what I'm trying to achieve on this link: http://madaxedesign. ...

Persistent navigation once fullscreen banner is completed

I have a full screen header on my one-page website. Below the hero section is the navigation element, which I want to be fixed after scrolling past the height of the full screen. Here's what I currently have in terms of code. HTML: <div id="hero" ...