我有一个 Select 框,我想在其中显示一个Font Awesome 6 caret.

我现在有这个代码,但插入符号不显示,即使认为字体真棒6是成功加载在网站上. See it live here.为什么不显示?

PS.我希望通过纯CSS来实现这一点,而不是通过更改select元素的HTML struct 来使其适用于任何地方.

    <div class="avada-select-parent">
        <select id="pa_ring-size" class="" name="attribute_pa_ring-size" data-attribute_name="attribute_pa_ring-size" data-show_option_none="yes">
            <option value="">Choose an option</option>
            <option value="14" class="attached enabled">14</option>
            <option value="14-5" class="attached enabled">14.5</option>
        </select>
        <div class="select-arrow" style="height: 38.4px; width: 38.4px; line-height: 38.4px;"></div>
    </div>
    /* Style for the select box */
    #pa_ring-size {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      background-color: white;
      border: 1px solid #ddd;
      padding: 10px 40px 10px 10px;
      border-radius: 5px;
      font-size: 16px;
      position: relative;
      width: 100%;
      box-sizing: border-box;
    }

    /* Style for the select arrow using ::after pseudo-element */
    #pa_ring-size::after {
      content: '\f0d7'; 
      font-family: 'Font Awesome 6 Pro';
      font-weight: 900; 
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      pointer-events: none;
    }

    .avada-select-parent {
      position: relative;
      display: inline-block;
    }

推荐答案

select:after-不起作用. 您有一个单独的箭头块,因此可以设置它的样式:

.avada-select-parent {
  --height: 40px;
  position: relative;
  display: inline-block;
}

#pa_ring-size {
  --padding:10px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: white;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 16px;
  width: 100%;
  box-sizing: border-box;
  height: var(--height);
  padding: 0 calc(var(--height) + var(--padding)) 0 var(--padding);
}

.select-arrow {
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--height);
  display: grid!important;
  place-items: center;
  pointer-events: none;
  font-size: 0!important;
  color: black!important;
}

.select-arrow:before {
  content: "\f0d7";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 16px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"/>
<div class="avada-select-parent">
  <select id="pa_ring-size" class="" name="attribute_pa_ring-size" data-attribute_name="attribute_pa_ring-size" data-show_option_none="yes">
    <option value="">Choose an option</option>
    <option value="14" class="attached enabled">14</option>
    <option value="14-5" class="attached enabled">14.5</option>
  </select>
  <div class="select-arrow" style="height: 38.4px; width: 38.4px; line-height: 38.4px;"></div>
</div>

Html相关问答推荐

使用Scrapy Select 最后一个子文本

当表头包含特殊字符时,R Quarto发布的HTML表中不必要的大列宽

在浮动元素旁边垂直居中

为什么在CSS中字段是一个有效的 colored颜色 名称?

Angular 滑块问题

有没有一种方法可以动态地从网格或Flexbox中取出HTML元素?

如何使用CSS在<;表格中<;SVG&>?

在Vue 3中使用v-Bind将计算(computed)属性传递给css url()

带有排序元素的 CSS 网格

带有图像的虚线边框

当浏览器宽度减小时字体大小变得太大

停止 Bootstrap 5 输入调整 CSS 网格单元的高度

四开将一个 qmd 文档中的单词链接到另一个 qmd 文档中的单词

在 vscode 中找不到 htmltagwrap 命令

使用 Selenium for Python 在网站上查找类名称中包含换行符的元素

如何创建带有偏移边框线的双色边框?

无法从社交栏中 Select 选项

两个按钮范围滑块的 CSS

我可以将两个元素之间的所有空间都放在弹性框或网格中吗?

根据正则表达式 attr 从 read_html 过滤表格