简体   繁体   English

自定义 Select 框与 ul li 与字体真棒图标

[英]Custom Select Box with ul li with font awesome icons

I am trying to make a custom select box to style it my way.我正在尝试制作一个定制的 select 盒子来按我的方式设计。 everything is going right but when I select anything from the dropdown the text shows up but the icon within doesn't.一切正常,但是当我 select 时,下拉菜单中的任何内容都会显示,但里面的图标没有。 I am also new to jQuery.我也是 jQuery 的新手。 the thing I want is the icon to show up as well when I select something from the dropdown.我想要的是当我从下拉列表中 select 时也显示图标。

Any help will be 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>

在此处输入图像描述

please add a link as below, on the HEAD.请在 HEAD 上添加如下链接。 I hope this helps我希望这有帮助

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

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

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