FontAwesome in <select>

Viewed 165

I'm trying to change the default arrow for a select dropdown (right hand side in the below photo). My current code is the following:

<script src='https://kit.fontawesome.com/a076d05399.js'></script>

<select id="wgtmsr" style="width: 230px !important; min-width: 230px; max-width: 230px; font-size: 18px; height: 59px;" name="wgtmsr";><i class="fas fa-arrow-circle-down">

<option class="_self" selected="selected" value="#">MAKES SERVICED</option>
    
</select>

Which results in the following: no icon appears

1 Answers

<select id="wgtmsr" style="width: 230px !important; min-width: 230px; max-width: 230px; font-size: 18px; height: 59px;" name="wgtmsr";><i class="fas fa-arrow-circle-down">

<option class="_self" selected="selected" value="#">MAKES SERVICED</option>
    
</select>

<style>
#wgtmsr {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg aria-hidden='true' focusable='false' data-prefix='fas' data-icon='arrow-circle-down' class='svg-inline--fa fa-arrow-circle-down fa-w-16' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='currentColor' d='M504 256c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-143.6-28.9L288 302.6V120c0-13.3-10.7-24-24-24h-16c-13.3 0-24 10.7-24 24v182.6l-72.4-75.5c-9.3-9.7-24.8-9.9-34.3-.4l-10.9 11c-9.4 9.4-9.4 24.6 0 33.9L239 404.3c9.4 9.4 24.6 9.4 33.9 0l132.7-132.7c9.4-9.4 9.4-24.6 0-33.9l-10.9-11c-9.5-9.5-25-9.3-34.3.4z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 100% 50%;
  background-size: 1em;
}
</style>

Element <select> does allow only tag <option> inside, pls see here Can I use HTML tags in the options for select elements?

As I understand - you want to add icon to <select>, you can do this using CSS background, you can to use svg in base64 or to style background of like any other element (e.g. to use jpg/png image).
Also needs to reset default select browser styles using appearance: none;

UPDATE
I downloaded icon as svg file which you wanted to use and used it as background.
One thing: I converted it to base64 to does not use external images, but it's does not required - as I said you can to use as background image file.

Related