简体   繁体   English

如何使用fontawesome图标更改select标签内的箭头图标。 我正在使用Vue-Cli。 我在main.js中导入了fontawesome

[英]How do I change the arrow icon inside the select tag with a fontawesome icon. I am using Vue-Cli. I have imported fontawesome in main.js

I am using vue-cli. 我正在使用vue-cli。 I am pretty new to vue. 我很陌生。 I am trying to change the arrow symbol in the right corner of the select tag. 我正在尝试更改选择标记右角的箭头符号。 How can I do it? 我该怎么做? I tried searching for a solution and got that I need to use css. 我尝试寻找解决方案,并得到我需要使用CSS。 But how can we use font-awesome in css? 但是我们怎样才能在css中使用font-awesome?

A good point of reference for styling form fields is wtfForms.com 样式表单字段的一个很好的参考点是wtfForms.com

There's many ways of doing this. 有很多方法可以做到这一点。 But if you're using Font Awesome across your whole site and need access to multiple icons in your CSS, you can import the CSS stylesheet. 但是,如果您在整个站点中使用Font Awesome并需要访问CSS中的多个图标,则可以导入CSS样式表。 Info here: https://fontawesome.com/start 信息: https//fontawesome.com/start

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">

Then you can set a pseduo element's font-family to the Font Awesome font, and use an icon's unicode in the content of that pseudo element. 然后,您可以将pseduo元素的font-family设置为Font Awesome字体,并在该伪元素的content中使用图标的unicode。 If you browse the icons on the Font Awesome website, each icon has a unicode listed toward the top of the page. 如果您浏览Font Awesome网站上的图标,则每个图标都会在页面顶部列出一个unicode。

Info on using Font Awesome in pseudo elements 有关在伪元素中使用Font Awesome的信息

.example::before {
  font-family: "Font Awesome 5 Free";
  content: "\f007";
}

For your use case, referencing the way wtfForms does it, you have to wrap the select input in another element. 对于您的用例,引用wtfForms的方式,您必须将select输入包装在另一个元素中。 You apply your styling (and pseudo icon) to that element, while hiding the original select input. 您将样式(和伪图标)应用于该元素,同时隐藏原始选择输入。

 .select { position: relative; display: inline-block; color: #555; } .select select { padding: .5em 2.25em .5em 1em; -webkit-appearance: none; -moz-appearance: none; appearance: none; } .select:after { position: absolute; top: 25%; right: .5em; font-family: "Font Awesome 5 free"; content: "\\f358" } 
 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous"> <div class="select"> <select aria-label="Select menu example"> <option selected>Open this select menu</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> </div> 

But read through what wtfForms has to say. 但请阅读wtfForms所说的内容。 There are some caveats and accessibility concerns with this, which they outline on their site. 这有一些警告和可访问性问题,他们在他们的网站上列出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM