html - 自定义 HTML 选择箭头图像

标签 html css stylesheet

我想隐藏 html 选择列表的默认箭头并向列表添加自定义图像(箭头)。

See the Picture

.form-inline select {
            margin: 10px 35px 15px 0px;
            background-color: #fff;
            font-size: 30px;
            width: 80px;
            color: #000;
            background-image: url("https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-512.png") center bottom no-repeat;
            cursor: pointer;
            display: block;
            outline: none;
            -webkit-appearance: none;
            appearance: none;
            border: none !important;
            justify-content:center;
            align-items:center;
            text-align:center;
        } 

这是我目前的风格。它没有按我的意愿显示箭头。请帮帮我。

最佳答案

您将 backgroundbackground-image CSS 样式混合在一起,难怪您的样式不起作用:

简短版本:(我正在使用 background 而不是 background-image)

background: salmon url("https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-512.png") no-repeat center calc(100% - 2px);
background-size: 24px 24px;

但我推荐这种方式,以便于修改:

background-color: #fff;
background-image: url("https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/down4-512.png");
background-size: 24px 24px;
background-repeat: no-repeat;
background-position: center calc(100% - 2px);

仅供引用,此 CSS 部分将隐藏浏览器的默认箭头:

-webkit-appearance: none;
appearance: none;

关于html - 自定义 HTML 选择箭头图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59525310/

相关文章:

android - HTML anchor 标记(在 jquery mobile 中)在 Android 上不起作用

html - 悬停效果超出边界

html - 元素上有很多 CSS 类还是一个特定类?

javascript - 点击显示不同的内容

html - 样式定义水平列表,术语在定义之上

javascript - 如何在 zf2 Controller 中附加 css 和 javascript 文件?

python - 如何在django中循环访问用户对象

html - 如何设置按钮背景,使其占用父div的高度和宽度?什么CSS属性会影响哪个维度?

html - 如何使语义用户界面中的固定顶部菜单不覆盖内容

css - 我怎样才能使我的 css 文件可用于我在 Gwt 中的整个应用程序?