Unique Select Menu featuring list items with Font Awesome icons

Trying my hand at creating a customized select box to match my style. Everything seems to be going well, except for one issue - when I make a selection from the dropdown, the text displays but the icon remains hidden. As someone who is new to jQuery, I'm seeking guidance on how to ensure that the icon also appears when an item is selected.

Any assistance on this matter would be greatly appreciated.

$('.select').click(function() {
  $(this).attr('tabindex', 1).focus();
  $(this).toggleClass('active');
  $(this).find('.select-menu').slideToggle(300);
});

$('.select').focusout(function() {
  $(this).removeClass('active');
  $(this).find('.select-menu').slideUp(300);
});

$('.select .select-menu li').click(function() {
  $(this).parents('.select').find('span').text($(this).text());
});
.select {
  background-color: rgb(255, 255, 255);
  width: 300px;
  height: 70px;
  position: relative;
  display: inline-block;
  border-radius: 50px;
  margin-top: 25px;
}

.select .select-inner {
  width: 100%;
  line-height: 70px;
  border: 0;
  padding: 0 20px;
  list-style: none;
  border-radius: 50px;
  cursor: pointer;
  padding: 0;
}

.select .select-inner:focus {
  outline: none;
}

.select ul {
  overflow: hidden;
  position: absolute;
  left: 0;
  list-style: none;
  cursor: pointer;
  display: none;
  overflow-y: auto;
  width: 100%;
  margin-top: 10px;
  line-height: 50px;
  min-height: 50px;
  background-color: inherit;
  border: 0;
}

.select:focus-visible {
  outline: none;
}

.select .select-inner .select-icon {
  position: absolute;
  left: calc(100% - 32px);
  line-height: 70px;
}

.select .select-inner i,
.select .select-menu i {
  background-image: -moz-linear-gradient(14deg, rgb(103, 23, 205) 0%, rgb(40, 113, 250) 60%);
  background-image: -webkit-linear-gradient(14deg, rgb(103, 23, 205) 0%, rgb(40, 113, 250) 60%);
  background-image: -ms-linear-gradient(14deg, rgb(103, 23, 205) 0%, rgb(40, 113, 250) 60%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 15px;
  margin-right: 15px;
}

.select .select-inner span,
.select .select-menu {
  font-size: 18px;
  color: rgb(27, 27, 27);
  padding: 0 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<div class="select">
  <div class="select-inner">
    <span><i class="fa-solid fa-hashtag"></i>Select Platform</span>
    <i class="select-icon fa-solid fa-sort-down"></i>
  </div>
  <ul class="select-menu">
    <li id="facebook"><i class="fa-brands fa-facebook-f"></i>Facebook</li>
    <li id="Instagram"><i class="fa-brands fa-instagram"></i>Instagram</li>
  </ul>
</div>

Answer №1

To improve the design, you can insert a link in the HEAD section using the code snippet provided below:

<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css"
/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I need help figuring out how to send a POST/GET request from AJAX to a custom module controller in Odoo 10, but I'm running into issues

I have implemented a custom module in Odoo 10 with a simple controller. Everything works smoothly when accessing http://127.0.0.1:8069/cmodule/cmodule through the browser, displaying the expected return string. However, I encountered an issue when attempt ...

Replace the original variable with the output of the .split() function

When splitting variables that have already been split and overwriting the original variable, is there potential for any issues? For example: arr = str.split(" "); arr = arr[0].split("/"); I have tested this and it seems to work. However, I am wondering: ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

What could be causing the partial transparency in my SVG mask?

I have been working on an interesting SVG code that creates a rectangle with a cutout circle. However, I am facing an issue where the non-cutout part appears to be partially transparent. https://i.sstatic.net/1PLHL.gif Can anyone provide me with guidance ...

Arranging Form Elements with Bootstrap styling

Check out the Bootply I created to demonstrate an issue I'm facing: http://www.bootply.com/8fPmr31Wd7 When scrolling down, you'll notice that "People" and "Places" are indented on the sides. It's possible that I'm not using the correc ...

"Discover the process of incorporating two HTML files into a single HTML document with the help of

I successfully created both a bar chart and a pie chart using d3.js individually. Now, I am trying to load these charts into another HTML file using jQuery. $(document).ready(function() { console.log("ready!"); $("#piediv").load("file:///usr/local ...

Is there an alternative module available for running Express APIs from Azure V4 functions, besides the "azure-aws-serverless-express" module?

Encountering an issue where the request URL is coming up as undefined when calling execute from Azure Function Model V4, auzurev4\src\functions\httpTrigger1.ts import { InvocationContext, HttpRequest } from "@azure/functions"; imp ...

Tips for integrating Bootstrap with ReactJS

As a newcomer to the world of React.js, I find myself unsure of how Bootstrap integrates with React. While researching, I came across npm packages like reactstrap and react-bootstrap, but I still don't quite understand. The HTML code seems to be gene ...

Navigating through Next.js for slug URLs such as site.com/username

Can someone help me figure out how to create a profile page for each username, like site.com/jack or site.com/jill? I'll be pulling the username info from an API that also contains the user ID and email. I'm new to Next.js and would really appre ...

Angular Universal Resolve

I am trying to ensure that an asynchronous call completes before any of my routes are resolved by modifying route.resolve as follows: var originalWhen = $routeProvider.when; $routeProvider.when = function(path, route) { route.resolve || (route.resolve ...

Can you advise on how to generate a key to access an environment.ts value within a *ngFor loop? Specifically, I am trying to locate keys that follow the pattern 'environment.{{region}}_couche_url' within the loop

I currently have a block of HTML code that is repeated multiple times. <!-- Metropolitan Map --> <div> <app-map [name] = "(( environment.metropole_name ))" [layer_url] = "(( environment.metropole_layer_url ))" ...

Having trouble running tests on the Express.js server

I'm struggling to run basic tests on my expressjs server and close it immediately. I have exported the server as a promise, but can't seem to figure out how to achieve this. Below is the code for my server file : index.js const config = require( ...

Adjust the navigation height to be proportional to the main content size

I've been attempting to make my navigation menu take up the entire page, but I have yet to achieve success: My goal is for the green menu section to extend down to the footer. Here is the HTML code: <div ...

What is the best way to divide a string within an object using JavaScript?

Currently, I have two objects in my possession obj1-> [ 'logo', 'FinTech startup', 'design' ] obj2-> [ 'logo', 'tech startup', 'design' ] Is there a quick method to transform them into ob ...

Displaying Stats.js inside a different canvas using ThreeJS

Just starting out with Three.js and wanted to test displaying the Stats.js in a small scenario. Check it out here Decided not to use modules for now, but followed similar code structure as in the examples: var stats = new Stats(); var renderer = ...

Ways to inform a subelement that a task is complete?

I have a child component that displays a list of orders passed from the parent. I want to include a "Reload" button inside the child component that, when clicked, triggers a function in the parent component to reload the orders. Upon clicking the reload b ...

Encountering a predicament when attempting to retrieve an image from an alternative

[index.jsp][5] style.css [problem][6] [folder hierarchy][7] Although everything runs smoothly when the file is located in the css directory, it fails to show any images if placed in the images folder. Kindly provide assistance. ...

Ways to recognize an element using selenium despite having an identical xpath

Currently, I am exploring selenium and attempting to automate a web application using the junit framework. Similar to many others, I am facing an issue with identifying web elements. My particular challenge arises from two submit buttons that share the sam ...

Difficulty aligning two images in one div using HTML and CSS

Having trouble with HTML and CSS. I have a div containing 2 images - one for background and the other for an avatar image that I can't seem to center. I've tried using margin:0 auto; and display:block; but it's not working. Current HTML pag ...

Unable to receive a response from a PHP API using AJAX jQuery with a GET request

As I work on retrieving data while a person types text using a "keyup" event in jQuery, I have encountered an issue while searching the database for matching words. The PHP API is not responding, showing an error: 404 - Not found. Having minimal exper ...