How to customize the arrow of a select

Asked

Viewed 7,577 times

9

I have a price list, it has a select for the person to choose the payment cycle as shown in the image:

which I did with CSS:

-webkit-appearance:none; 
background:#E9E9E9 url("../imagens/bgs/seta.png") 95.5% 50% no-repeat;

As shown in this image only works in Google Chrome:

I would like to do the same of the second image and that works in all browsers, maybe I can do with Javascript?

1 answer

6

Unfortunately it is still not possible to do this in the "right way" on all browsers, since the property appearance is not ubiquitous.

Support from current browsers: Browser Support

For now, it’s important to maintain a fallback, but you can increase support by also adding the prefix -moz.

-webkit-appearance: none;
-moz-appearance:    none;
appearance:         none;

Some developers include the tag select within a div and stylize it, as in the example:

<div class="select">
  <select>
    ...
  </select>
</div>
select {
  -webkit-appearance: none;
  -moz-appearance:    none;
  appearance:         none;
  width: 100%;
}

.select {
  ...
  background: #e9e9e9 url('../imagens/bgs/seta.png') 95.5% 50% no-repeat;
  ...
}

This method may increase compatibility, although it is not yet a solution cross-browser.


Or, use a Javascript library like Select2.

  • Interesting, I didn’t know it. But from what I saw in MDN, it seems that this property was cut from the draft specification, so it will hardly be cross-browser one day.

  • 1

    @bfavaretto: You are right, this specification is known as System Appearance and was proposed in the CSSS3-UI Candidate Recommendation on 11/05/2004, but never got off the ground. It is very unlikely that the property appearance be present at CSS4-UI As we know it today, the reality is that ten years have passed, many components (mainly forms) have been added to HTML5 and this makes clear the need for the rewinding and rewriting of the problems that were originally designed to solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.