CSS 如何在 Mac 上的 Safari 中删除所选元素上的光泽?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7638677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 01:48:25  来源:igfitidea点击:

How can I remove the gloss on a select element in Safari on Mac?

cssmacossafaridrop-down-menubackground-color

提问by Ian Hunter

On Macs and iOS devices, in Safari, a <select>element with a background color generates a gloss over itself. This does not seem to happen in other operating systems.

在 Mac 和 iOS 设备上,在 Safari 中,<select>具有背景颜色的元素会为其自身生成光泽。这在其他操作系统中似乎不会发生。

For example, I have a select element with these style properties:

例如,我有一个具有以下样式属性的 select 元素:

select {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
padding: 3px 6px;
margin: 10px 0 7px;
width: 250px;
background-color: #BD2786;
color: white;
letter-spacing: -.04em;
font-weight: bold;
border: 0;
}

And my element has the background color I want, but the gloss is still there. Does anyone know how to make it a flat color?

我的元素有我想要的背景颜色,但光泽仍然存在。有谁知道如何使它成为平坦的颜色?

回答by sandeep

@beanland; You have to write

@beanland; 你必须写

-webkit-appearance:none;

in your css.

在你的 css 中。

read this http://trentwalton.com/2010/07/14/css-webkit-appearance/

阅读此http://trentwalton.com/2010/07/14/css-webkit-appearance/

回答by alicjasalamon

Using -webkit-appearance:none;will remove also the arrows indicating that this is a dropdown.

使用-webkit-appearance:none;还将删除指示这是下拉列表的箭头。

See this snippet that makes it work across different browsers an adds custom arrows without including any image files:

请参阅此代码段,使其在不同浏览器中工作并添加自定义箭头而不包含任何图像文件:

select{
 background: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0Ljk1IDEwIj48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6I2ZmZjt9LmNscy0ye2ZpbGw6IzQ0NDt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPmFycm93czwvdGl0bGU+PHJlY3QgY2xhc3M9ImNscy0xIiB3aWR0aD0iNC45NSIgaGVpZ2h0PSIxMCIvPjxwb2x5Z29uIGNsYXNzPSJjbHMtMiIgcG9pbnRzPSIxLjQxIDQuNjcgMi40OCAzLjE4IDMuNTQgNC42NyAxLjQxIDQuNjciLz48cG9seWdvbiBjbGFzcz0iY2xzLTIiIHBvaW50cz0iMy41NCA1LjMzIDIuNDggNi44MiAxLjQxIDUuMzMgMy41NCA1LjMzIi8+PC9zdmc+) no-repeat 95% 50%;
 -moz-appearance: none; 
 -webkit-appearance: none; 
 appearance: none;
    /* and then whatever styles you want*/
 height: 30px; 
 width: 100px;
 padding: 5px;
}
<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

回答by Noel Abrahams

2019 Version

2019版

Shorter inline image URL, shows only down arrow, customisable arrow colour...

更短的内嵌图片 URL,仅显示向下箭头,可自定义的箭头颜色...

From https://codepen.io/jonmircha/pen/PEvqPa

来自https://codepen.io/jonmircha/pen/PEvqPa

Author is probably Jonathan MirCha

作者可能是Jonathan MirCha

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%238C98F2'><polygon points='0,0 100,0 50,50'/></svg>") no-repeat;
  background-size: 12px;
  background-position: calc(100% - 20px) center;
  background-repeat: no-repeat;
  background-color: #efefef;
}

回答by Justin Edwards

Sorry to pile on to an old item. I found partial answers to my questions here but had to do some work so I wanted to share my results for the next person.

很抱歉堆到一个旧项目上。我在这里找到了我问题的部分答案,但不得不做一些工作,所以我想为下一个人分享我的结果。

I ended up using the same approach as the other contributors, but with a few tweaks to fix the following

我最终使用了与其他贡献者相同的方法,但进行了一些调整以解决以下问题

  1. Long text was covering the arrows in the other solutions
  2. The image being used was a somewhat old and ugly up/down combo arrow.
  1. 长文本覆盖了其他解决方案中的箭头
  2. 使用的图像是一个有点旧和丑陋的向上/向下组合箭头。

The below will give you a working solution with the above issues fixed. Note: I used a white arrow for my use case, you may need to change the color of the arrow for yours.

下面将为您提供解决上述问题的有效解决方案。注意:我在我的用例中使用了白色箭头,您可能需要为自己更改箭头的颜色。

here's a preview:

这是一个预览:

select with white arrow

用白色箭头选择

select{    
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgICB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZGktMC5kdGQiICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiICAgaWQ9IkxheWVyXzEiICAgZGF0YS1uYW1lPSJMYXllciAxIiAgIHZpZXdCb3g9IjAgMCA0Ljk1IDEwIiAgIHZ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dy1tYXhpbWl6ZWQ9IjEiICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJMYXllcl8xIiAvPiAgPGRlZnMgICAgIGlkPSJkZWZzNDE5MCI+ICAgIDxzdHlsZSAgICAgICBpZD0ic3R5bGU0MTkyIj4uY2xzLTJ7ZmlsbDojNDQ0O308L3N0eWxlPiAgPC9kZWZzPiAgPHRpdGxlICAgICBpZD0idGl0bGU0MTk0Ij5hcnJvd3M8L3RpdGxlPiAgPHBvbHlnb24gICAgIGNsYXNzPSJjbHMtMiIgICAgIHBvaW50cz0iMy41NCA1LjMzIDIuNDggNi44MiAxLjQxIDUuMzMgMy41NCA1LjMzIiAgICAgaWQ9InBvbHlnb240MTk4IiAgICAgc3R5bGU9ImZpbGw6I2ZmZmZmZjtmaWxsLW9wYWNpdHk6MSIgLz48L3N2Zz4=) no-repeat 101% 50%;
  padding-right:20px;
}

回答by Joansy

Check out -webkit-appearance: none and its derivatives. Originally described by Chris Coyer here: https://css-tricks.com/almanac/properties/a/appearance/

查看 -webkit-appearance: none 及其衍生物。最初由 Chris Coyer 在这里描述:https://css-tricks.com/almanac/properties/a/appearance/

回答by Surajnaikin

If you inspect the User Agent StyleSheet of Chome, you'll find this

如果你检查 Chome 的用户代理样式表,你会发现这个

outline: -webkit-focus-ring-color auto 5px;

in short its outline property - make it None

简而言之,它的轮廓属性 - 使其成为无

that should remove the glow

那应该消除辉光