<select> 中的 FontAwesome
FontAwesome in <select>
我正在尝试更改 select 下拉菜单的默认箭头(下图右侧)。我当前的代码如下:
<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>
结果如下:no icon appears
<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>
元素<select>
只允许标签<option>
在里面,请看这里
Can I use HTML tags in the options for select elements?
据我了解-您想将图标添加到 <select>
,您可以使用 CSS background 来完成此操作,您可以在 base64 中使用 svg或像任何其他元素一样设置背景样式(例如使用 jpg/png 图像)。
还需要使用 appearance: none;
重置默认 select 浏览器样式
更新
我将图标下载为您要使用的 svg 文件并将其用作背景。
一件事:我将它转换为 base64 以不使用外部图像,但这不是必需的 - 正如我所说,您可以将其用作背景图像文件。
我正在尝试更改 select 下拉菜单的默认箭头(下图右侧)。我当前的代码如下:
<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>
结果如下:no icon appears
<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>
元素<select>
只允许标签<option>
在里面,请看这里
Can I use HTML tags in the options for select elements?
据我了解-您想将图标添加到 <select>
,您可以使用 CSS background 来完成此操作,您可以在 base64 中使用 svg或像任何其他元素一样设置背景样式(例如使用 jpg/png 图像)。
还需要使用 appearance: none;
更新
我将图标下载为您要使用的 svg 文件并将其用作背景。
一件事:我将它转换为 base64 以不使用外部图像,但这不是必需的 - 正如我所说,您可以将其用作背景图像文件。