javascript - 单击“选择”选项时如何更改箭头方向

标签 javascript html css bootstrap-4

I want the arrow to move up when I open the select dropdown option.

<select class="form-select" aria-label="Default select example">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

最佳答案

来,试试这个,

select{
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/></svg>') no-repeat right #ddd;
    -webkit-appearance: none;
    padding-right: 1.5rem;
    background-position: right 0.1rem center;
}
select:focus {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-up" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M7.646 4.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 5.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"/></svg>') no-repeat right #ddd;
    background-position: right 0.1rem center;
}
<select class="form-select" aria-label="Default select example">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

图标来自 bootstrap,Chevron upChevron down

关于javascript - 单击“选择”选项时如何更改箭头方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70603454/

相关文章:

css - markdown调整列大小并在行之间添加断行

javascript - 在python服务器端解析json

javascript - AngularJs。 ng-repeat 的问题

html - 共享元标记 og :image for facebook is selecting other image then defined

css - 如何在表单左侧显示内容

CSS:Bootstrap - 移动浏览器的粘性页脚错误位置

javascript - 匹配谷歌日历事件提要日期的正则表达式

javascript - 如何让按键在输入字段上不起作用

html - 为什么 CSS 类被忽略了?

javascript - 在构建这个 jQuery 时需要帮助