简体   繁体   English

为什么CSS“字体家族:继承”会影响字体的颜色 <select>在Chrome中? (带有示例)

[英]Why is css “font-family:inherit” affecting color of <select> in Chrome? (with example)

I was wondering why is <select> element different color on few web pages. 我想知道为什么<select>元素在几个网页上的颜色不同。 I noticed that on some pages if there is font-family:inherit css property affecting the select element, it would look different - blue! 我注意到在某些页面上,如果有font-family:inherit css属性影响select元素,则外观会有所不同-蓝色!

<!-- BLACK -->
<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<!-- BLUE -->
<select style="font-family: inherit;">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

JsFiddle with working example JsFiddle与工作示例

I understand frontend development, and I know about normalize/reset. 我了解前端开发,并且了解规范化/重置。 I am wondering why is font-family:inherit affecting color of a <select> 我想知道为什么font-family:inherit影响<select>颜色

Does anyone know why is it so? 有谁知道为什么会这样吗? What is the default value (ie inherit) value for the font-family? 字体系列的默认值(即继承)是什么?

Screenshot showing js fiddle result on mac 屏幕截图显示了在Mac上的js小提琴结果

EDIT: 编辑:

Tony posted a screenshot in comments, font-family: system-ui; Tony在注释中张贴了一个屏幕截图, font-family: system-ui; is affecting look and feel of <select> . 影响<select>外观。

EDIT 2: 编辑2:

Apparently it is a trend in web design to leave decision on font family to the device - so called native fonts. 显然,在网页设计中,将字体家族的决定权留给设备是一种趋势,即所谓的本机字体。 Therefore forms are also respecting directive and end up rendered as native UI elements. 因此,表单也遵循指令,并最终呈现为本机UI元素。

It is different depending on the browser you are using. 根据您使用的浏览器,它是不同的。 Each browser has their own default settings. 每个浏览器都有自己的默认设置。

You can find a list of default styles across all browsers here . 您可以在此处找到所有浏览器的默认样式列表。 When inspecting elements on chrome you can see default styles labeled as user agent stylesheet . 在chrome上检查元素时,您会看到标记为user agent stylesheet默认user agent stylesheet An example of this is seen below: 下面是一个示例:

在此处输入图片说明

Many people use a CSS reset file to standardize these settings across browsers. 许多人使用CSS重置文件来跨浏览器标准化这些设置。 The Eric Meyer's reset is a popular option to achieve this. Eric Meyer的重置是实现此目的的流行选择。

For whatever reason, the font-family property on form elements cannot be 100% predictably styled across all browsers. 无论出于何种原因,表单元素上的font-family属性都无法在所有浏览器中进行100%可预测的样式设置。 I'm not sure if it's a rendering or security reason but in the case of Chrome, the system-ui font seems to be the culprit here. 我不确定这是出于渲染还是出于安全原因,但对于Chrome, system-ui字体似乎是此处的罪魁祸首。

https://jsfiddle.net/8nr6h74o/3/ https://jsfiddle.net/8nr6h74o/3/

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

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