- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我们定义了一个font-family
,使用@font-face
:
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 900;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/oMMgfZMQthOryQo9n22dcuvvDin1pK8aKteLpeZ5c0A.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
上面的font-weight
似乎不是指定用户指定font-family: Roboto
时使用这个字体文件呈现什么重量,而是,当 @font-face
指定相同的名称时,它“匹配”使用哪个字体文件。
例子:
如果在 @font-face
中,我们指定 400
的 font-weight
,现在文本显示在 Google Chrome 中(版本 48.0,我可以在这个问题中使用当前的 Firefox 44.0.2 获得几乎相同的 jsfiddles 结果,光线不能更亮,但粗体可能是通过渲染“双重打印”技巧而变粗的像素的字体或“双倍宽度”:
https://jsfiddle.net/0vL8m9bj/
如果我们将 @font-face
中的 font-weight
设置为 900
,那么所有 3 行文本都将变为常规:
https://jsfiddle.net/0vL8m9bj/1/
所以我们可以看到900
不是指定要显示什么,而是使用那个字体文件。
那么@font-face
里面的font-weight
有什么用呢?
如果我们使用 https://www.google.com/fonts#UsePlace:use/Collection:Roboto并链接这一行:
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,900,300'
rel='stylesheet' type='text/css'>
这实际上会将一些 CSS 定义作为文件加载到浏览器中:
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfZBw1xU1rKptJj_0jans920.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/oMMgfZMQthOryQo9n22dcuvvDin1pK8aKteLpeZ5c0A.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 900;
src: local('Roboto Black'), local('Roboto-Black'), url(https://fonts.gstatic.com/s/roboto/v15/mnpfi9pxYH-Go5UiibESIpBw1xU1rKptJj_0jans920.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
/* other languages omitted here */
现在我们可以看到 3 个“权重”:
https://jsfiddle.net/0vL8m9bj/5/
但是,它不是按数字最接近的匹配——它看起来像按“light”、“normal”和“bold”类别匹配,因为如果它是 301
,它不会与 299
匹配,甚至认为它非常接近 299
,但会与 400
或 500< 匹配
:
https://jsfiddle.net/0vL8m9bj/6/
699
也不会与 700
匹配,但会与 400
匹配。
我们还可以看到,如果我们反转@font-face
的font-weight
,并使用bold
,normal
,lighter
为文字的样式,然后bold
使用light字体文件,lighter
使用深色字体文件:
https://jsfiddle.net/0vL8m9bj/10/
但是,奇怪的是,如果把上一个@font-face
中的700
改成701
,现在所有3行将变为粗体:
https://jsfiddle.net/0vL8m9bj/7/
所以真的很奇怪。似乎规则是:匹配3类权重,除了最后一个例子。
还有一件奇怪的事:如果.section1
是font-weight: 300
,它显示为light:
https://jsfiddle.net/0vL8m9bj/8/
但让它成为 font-weight: 299
-- 意思是更轻,现在它显示为粗体:
https://jsfiddle.net/0vL8m9bj/9/
所以让它更轻便使其更大胆。
那么@font-face
里面的font-weight
规则是什么?
最佳答案
你的假设是正确的。
@font-face
中的描述符与元素样式无关,仅与字体匹配相关。来自CSS Fonts Module Level 3 draft :
[4.1] The
@font-face
rule allows for linking to fonts that are automatically fetched and activated when needed. This allows authors to select a font that closely matches the design goals for a given page rather than limiting the font choice to a set of fonts available on a given platform. A set of font descriptors define the location of a font resource, either locally or externally, along with the style characteristics of an individual face....
Each
@font-face
rule specifies a value for every font descriptor, either implicitly or explicitly. Those not given explicit values in the rule take the initial value listed with each descriptor in this specification. These descriptors apply solely within the context of the@font-face
rule in which they are defined, and do not apply to document language elements. There is no notion of which elements the descriptors apply to or whether the values are inherited by child elements.
然后在第 4.4 节中:
[
font-style
,font-weight
andfont-stretch
] define the characteristics of a font face and are used in the process of matching styles to specific faces. For a font family defined with several @font-face rules, user agents can either download all faces in the family or use these descriptors to selectively download font faces that match actual styles used in document. The values for these descriptors are the same as those for the corresponding font properties except that relative keywords are not allowed, ‘bolder’ and ‘lighter’. If these descriptors are omitted, initial values are assumed....
这样做的好处是“RobotoBold”、“RobotoLight”等不需要font-family
名称。
关于css - 在css@font-face中,font-weight不是指定这个字体用什么粗细,而是用font-weight的3类到 "match"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35822846/
我希望深入了解 LightFM 实现的以下权重: 样本权重 什么是sample_weights在 fit方法?我读到它们是为了模拟时间衰减,但这究竟是如何工作的?解释这一点的示例或文章将非常有帮助。
如果这是一个愚蠢的问题,我预先道歉。 当调用 nw:weighted-path-to 时,会返回一个链接列表,描述起始海龟和目标海龟之间的最短路径。 类似地,调用 nw:turtles-on-weig
我阅读了以下代码: //talkback.c -- nosy, informative program #include #include //for strlen() prototype #d
我有这个示例 html 文件: Test font bold (weight = 700) Test font bold (weight = 900) 我不知道为什么如果我将
您好,我正在为我自己的数据集训练 VGG16 网络。下面给出了我使用的代码。 from keras.models import Sequential from scipy.misc import im
我刚看完the notes CNN 上的斯坦福 CS231n 和现场链接 demo ;然而,我不确定演示中的“激活”、“激活梯度”、“权重”和“权重梯度”指的是什么。 以下屏幕截图已从演示中复制。 混
我不明白 maxout 是如何工作的,我怀疑这是由于我对线性代数乘法的可视化造成的。基本上,我的印象是 maxout 函数有两组权重,均经过单独训练,然后只选择一组。但我怀疑这可能是错误的,因为我没有
我运行了 Tensorflow 1.0 提供的 ptb_word_lm.py,但它显示了这条消息: ValueError: Attempt to have a second RNNCell use t
我有一个关于 R 中的样本函数的简单问题。我从长度为 5 的输入向量中随机抽样 0 和 1 并将它们相加,该向量指定要运行的试验次数并设置种子以生成可重复的随机数字。种子按预期工作,但根据我在 pro
我有一个以“h5”格式保存的模型。在使用 编译模型后,我正在尝试恢复训练并尝试加载优化器的权重 model.optimizer.set_weights(weights_list) 哪里weights_
我正在尝试为我的大学项目开发电话分类器模型。我已经训练了我的模型,当我尝试通过执行 python app/server.pyserve 来部署模型时遇到了问题。我读了一篇文章( https://f
所以... var testArray=new Array("hello"); testArray.length=100; console.log(testArray.length); 我相信上面的内
在 css 规范中,什么会影响更多的 inline 样式或外部 !important 外部“style.css”: #di{color: green!important;} div 文本颜色是红色还
我正在使用 http://hughsk.github.io/colony/ 的调整后的代码,但我不断收到错误: Uncaught TypeError: Cannot read property 'we
我们有一个系统,它按表中的“优先级”编号处理记录。我们通过表的内容定义优先级,例如 UPDATE table SET priority=3 WHERE processed IS NULL UPDATE
我已经使用 Darkflow 和 yolov2.weights 进行了定制训练。 checkpoint 文件夹中有四个文件。它们是: 1.yolov2-3c-5500.data-00000-of-00
我需要将 weighted.mean 函数包含在另一个函数中,作为我正在处理的项目的一部分。我无法让 w 参数在我正在处理的函数中正常工作。 为了使我的整体功能正常工作,我需要满足使权重参数必须是可选
我想使用 ggplot 绘制加权 CDF。一些旧的非 SO 讨论(例如 2012 年的 this)表明这是不可能的,但我想我会重新加注。 例如,考虑以下数据: df <- data.frame(x=s
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: In Java, what is the best way to determine the size of an
我需要将 weighted.mean 函数包含在另一个函数中,作为我正在处理的项目的一部分。我无法让 w 参数在我正在处理的函数中正常工作。 为了使我的整体功能正常工作,我需要满足使权重参数必须是可选
我是一名优秀的程序员,十分优秀!