Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Icon in select options tag

Need to display Font Awesome in select options tag?

If i use outside Its working <i class="fas fa-chart-pie"></i> But how can i display it in tag instead if text

<select id="select_graphtype">
  <option value="line_graph"> Line Graph</option>
  <option value="pie_chart"> Pie Chart</option>
</select>

Can you please help me out ?

like image 624
Jhansi Pasupuleti Avatar asked Jan 02 '19 07:01

Jhansi Pasupuleti


People also ask

Can I put image in select option?

To display the images in the select drop-down we have to use javascript libraries. We can add an image in select options using "select2" jQuery library.

How do you style options in select tag?

Using the * CSS selector you can style the options inside the box that is drawn by the system. That is true only because the all selector targets the shadow DOM innards, you can target those manually per browser. This is not true, even If you use * you can just style the background and color.

How do I show icons in HTML?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)

Can you style a select tag in HTML?

A style attribute on a <select> tag assigns a unique style to the dropdown. Its value is CSS that defines the appearance of the dropdown control.


1 Answers

You can't use (icon tag) inside (option tag), but you can do it differently like use class='fa' in select and icon classes in option's value. It's fully working in my case.

<select id="select_graphtype" class="fa">
    <option value="fa fa-address-card"> &#xf2bb; line chart</option>
    <option value="fa fa-address-card"> &#xf2bb; Pie Chart</option>
</select>

If this is not working please ensure this

.fa option {

    font-weight: 900;
}

Hope this helps you. Better I would suggest you dashing frontend framework Materialize CSS select in this link.. I have been using it for my frontend works.

Image worked for me

like image 173
Mobasshir Bhuiya Avatar answered Oct 21 '22 13:10

Mobasshir Bhuiya