<option> Background Image Not Displaying

Can anyone tell me why the background image in this code does not display?

  • The image exists.
  • I’m trying to remove the text (which I know to use font-size: 0!important; or change the text color—prefer not to use visibility: hidden;)

I have read that this SHOULD work on all browsers, but I’m not getting any output on any browser.

However, the alternative I would like to go with is to use FontAwesome, but I can’t even get those to post within <option> unless they are selected. I also need to preserve the “value” instead of actually changing it to the Font Awesome classification.

If you take a look at #two at the very last option, I would like to get the unicode to work so I can replace the “value” back to what it should be ('value=“bookmarks”).

Open to suggestions!

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
    <style>
        div#one select option {
            background-repeat: no-repeat;
            background-position: center center;
        }
        div#one #seltrans {
            background-image: url("https://www.dgdtransport.com/wp-content/uploads/2019/01/transport-type.png");
        }
        div#one #localtrans {
            background-image: url("https://www.dgdtransport.com/wp-content/uploads/2019/01/export.png");
        }
        div#one #nationtrans {
            background-image: url("https://www.dgdtransport.com/wp-content/uploads/2019/01/export.png");
        }
        div#one #drayagetrans {
            background-image: url("https://www.dgdtransport.com/wp-content/uploads/2019/01/drayage.png");
        }
        div#two select {
            font-family: "Font Awesome 5 Free";
        }
    </style>
  </head>
  <body>
    <div id="one">
    <select name="input_6" id="input_26_6" class="small gfield_select form-control" tabindex="12" aria-required="true" aria-invalid="false">
        <option value="" selected="selected" class="gf_placeholder" id="seltrans">
    Select</option>
        <option value="Local/Last Mile/LTL" id="localtrans">Local/Last Mile/LTL</option>
        <option value="Nationwide Trucking" id="nationtrans">Nationwide Trucking</option>
        <option value="Container Drayage" id="drayagetrans">Container Drayage</option>
    </select>
    </div>
    <div id="two">
         <select name="input_6" id="input_26_6" class="small gfield_select form-control" tabindex="12" aria-required="true" aria-invalid="false">
        <option value="fas fa-building" selected="selected" class="gf_placeholder">
    Select</option>
        <option value="fas fa-address-card"></option>
        <option value="fas fa-bell"></option>
        <option value="fas fa-bookmark">&#xf02e;</option>
    </select>
    </div>
  </body>
</html>

So I started working with using Font Awesome and was able to make an adjustment, but not all of the icons are displaying (using v. 5.6.3). The only one displaying is the “&#xf0d1”. But even so, it doesn’t display unless it’s selected.

<style>
        select {
            font-family: "FontAwesome";
        }
    </style>
  </head>
  <body>
    <div id="one">
    <select name="input_6" id="input_26_6" class="small gfield_select form-control" tabindex="12" aria-required="true" aria-invalid="false">
        <option value="" selected="selected" class="gf_placeholder" id="seltrans">
    Select</option>
        <option value="Local/Last Mile/LTL" id="localtrans">&#xf0d1;</option>
        <option value="Nationwide Trucking" id="nationtrans">&#xf4de;</option>
        <option value="Container Drayage" id="drayagetrans">&#xe536;</option>
    </select>
    </div>
  </body>
</html>

Still trying to get it to work, you can check the page here. You will see an quote form. The first field called “Transportation” is where I need to get the icons to show up.

Hi,
It looks like you are still required to use <i class="fas"> when using the unicode.
So at it’s bare minimum I get the unicode to work with this.
<i class="fas">&#xf0d1;</i>

I am also able to use standard unicode in your options and they work fine. Just seems to be having trouble with the fontawesome unicodes since you can’t nest tags in the option element.

Permitted content - Text, possibly with escaped characters (like &eacute; ).

<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  <title>Test Page</title>
<style>
body {padding:20px}

select#input_26_6 {
    font-family: Arial, FontAwesome;
    margin:0 0 90px;
}
.fas {
  display:block;
  margin:2px 0;
}
</style>

</head>
<body>

<select name='input_6' id='input_26_6' class='small gfield_select' tabindex='12'  aria-required="true" aria-invalid="false">
  <option value='' selected='selected' class='gf_placeholder'>Select</option>
  <option value='Local/Last Mile/LTL' >&#xf0d1; &bull; Local/Last Mile/LTL</option>
  <option value='Nationwide Trucking' >&#xf0d1; &#9658; Nationwide Trucking</option>
  <option value='Container Drayage' >&#xf00a; &#9660; Container Drayage</option>
</select>

<p>Using fontawesome <code>i class="fas fa-truck"</code> and raw unicode</p>
<p><i class="fas fa-truck"></i> &#xf0d1;</p>
<p><i class="fas fa-truck"></i> &#xf0d1;</p>
<p><i class="fas fa-th"></i> &#xf00a;</p>

<p>Using fontawesome <code>i class="fas"</code> with nested unicode</p>
<i class="fas">&#xf0d1;</i>
<i class="fas">&#xf00a;</i>

</body>
</html>

1 Like

But I need to use the Font Awesome icons for the <option> elements. Supposedly it’s usable, but I can’t get them to display unless the user selects the option. It is at that point the icon displays.

If you use a different version it all works.

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/>

e.g.

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet"/>

<title>Test Page</title>
<style>
body {
	padding:20px
}
select#input_26_6 {
	font-family: Arial, FontAwesome;
	margin:0 0 90px;
}
.fas {
	display:block;
	margin:2px 0;
}
</style>
</head>
<body>
<select name='input_6' id='input_26_6' class='small gfield_select' tabindex='12'  aria-required="true" aria-invalid="false">
  <option value='' selected='selected' class='gf_placeholder'>Select</option>
  <option value='Local/Last Mile/LTL' >&#xf042;  &#xf0d1; &bull; Local/Last Mile/LTL</option>
  <option value='Nationwide Trucking' >&#xf0d1; &#9658; Nationwide Trucking</option>
  <option value='Container Drayage' >&#xf00a; &#9660; Container Drayage</option>
</select>
</body>
</html>

Doesn’t seem to be working in Firefox:

FIREFOX 64.0:
firefox

CHROME 71.0.3578.98 & IE 11.0.9600:
Chrome

No it doesn’t seem to work in Firefox. I’m not sure if that is a crossorigin policy either as the selected icon shows up as an icon in Firefox.

1 Like

Bummer.

I was testing in Firefox, so that’s what I had based my conclusions on.

1 Like

I believe there are issues in OS also so I think the only fullproof way to add icons is to use a select replacement technique (although its a lot of work).

IOS bug:

https://bugs.chromium.org/p/chromium/issues/detail?id=568116

Yeah. I was hoping for something simple, knowing the limitation of the <option> tag.

Thanks for verifying, gents! It’ll just have to be unfriendly with Firefox.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.