初学者问题:如何在同一样式表中为相同字体使用不同的字重?

huangapple go评论61阅读模式
英文:

Beginner Question: How to use different font weights for the same font in the same stylesheet?

问题

我已经两次添加了字体“Acumin Pro Condensed”,分别使用了不同的字重;400 和 700。

我尝试过分别应用这两种字重的字体,将 400 应用于 h3 标签,将 700 应用于 h2 标签,但只有 700 字重的字体被应用。

@font-face {
	font-family: 'Acumin Pro Condensed';
	src: url('../fonts/Acumin\ Pro\ Condensed.woff2') format('woff2'),
		url('../fonts/Acumin\ Pro\ Condensed.woff') format('woff'),
		url('../fonts/Acumin\ Pro\ Condensed.ttf') format('truetype');
	font-weight: 700;
	font-style: normal;
}

@font-face {
	font-family: 'Acumin Pro Condensed';
	src: url('../fonts/Acumin\ Pro\ Condensed.woff2') format('woff2'),
		url('../fonts/Acumin\ Pro\ Condensed.woff') format('woff'),
		url('../fonts/Acumin\ Pro\ Condensed.ttf') format('truetype');
	font-weight: 400;
	font-style: normal;
}

h3 {
	font-size: 1em;
	color: white;
	font-family: 'Acumin Pro Condensed';
	font-weight: 400;
	text-transform: uppercase;
}

h2 {
	font-size: 1.25em;
	color: white;
	font-family: 'Acumin Pro Condensed';
	font-weight: 700;
}

我尝试过更改字体名称为不同的名称,但似乎也不起作用。

英文:

I have added the font face Acumin Pro Condensed twice, both with different font-weights; 400 and 700.

I have tried to apply the font with both seperate weights, 400 on a h3 tag and 700 on a h2 tag, however only the 700 font weight is being applied.

@font-face {
font-family: 'Acumin Pro Condensed';
src: url('../fonts/Acumin\ Pro\ Condensed.woff2') format('woff2'),
	url('../fonts/Acumin\ Pro\ Condensed.woff') format('woff'),
	url('../fonts/Acumin\ Pro\ Condensed.ttf') format('truetype');
font-weight: 700;
font-style: normal;
} 

@font-face {
font-family: 'Acumin Pro Condensed';
src: url('../fonts/Acumin\ Pro\ Condensed.woff2') format('woff2'),
	url('../fonts/Acumin\ Pro\ Condensed.woff') format('woff'),
	url('../fonts/Acumin\ Pro\ Condensed.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}

h3 {
font-size: 1em;
color: white;
font-family: 'Acumin Pro Condensed';
font-weight: 400;
text-transform: uppercase;
}

h2 {
font-size: 1.25em;
color: white;
font-family: 'Acumin Pro Condensed';
font-weight: 700;
}

I have tried changing the name of the font-family to something different but that doesn't seem to work either.

答案1

得分: 0

我相信你是为两者定义了相同的字体。(请看这个)

在你的 font-family 绑定中,你在说:

一个名为 Acumin Pro Condensed 的字体系列,带有 font-weight: 700 在这里:

src: url('../fonts/Acumin Pro Condensed.woff2') format('woff2'),
    url('../fonts/Acumin Pro Condensed.woff') format('woff'),
    url('../fonts/Acumin Pro Condensed.ttf') format('truetype')

然后你也为 400 的字体系列说了同样的事情。当你在字体系列绑定中指定了字体的粗细,你只是在标识它,以便以后可以使用它,而不是改变它的粗细。

如果你想要有更粗或更细的 Acumin Pro Condensed 版本,你需要找到不同的 src 地址。实际上,你并没有添加 700 和 400 的粗细,而是两次添加了相同的字体,并说不管你要求 700 还是 400,都使用相同的字体。

最棒的是,你让它按照预期的方式工作了,只是你没有得到你想要的结果。所以只需找到另一种字体(更粗或更细),切换源文件地址以匹配它,你就可以继续了!
1: https://stackoverflow.com/questions/40919389/cost-of-font-family-vs-font-weight

英文:

I believe you're defining the same font for both. (See this)

In your font-family bindings, you're saying:

A font-family called Acumin Pro Condensed with font-weight: 700 is here:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

src: url(&#39;../fonts/Acumin\ Pro\ Condensed.woff2&#39;) format(&#39;woff2&#39;),
    url(&#39;../fonts/Acumin\ Pro\ Condensed.woff&#39;) format(&#39;woff&#39;),
    url(&#39;../fonts/Acumin\ Pro\ Condensed.ttf&#39;) format(&#39;truetype&#39;)

<!-- end snippet -->

Then you're saying the same thing for a weight of 400. When you specify a weight in a font-family binding, you're identifying it so you can use it later, not changing it's weight.

If you want to have a bolder or lighter version of Acumin Pro Condensedyou would need to find a different src for it. You haven't actually added both 700 and 400 weights, you've added the same font twice and said use the same thing whether you ask for 700 or 400.

The great thing is, you got it to work as it's supposed to, you just didn't get the result you wanted. So just find that other font (heavier or lighter), switch the source file address to match and you'll be good to go!

huangapple
  • 本文由 发表于 2023年2月10日 06:51:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405265.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定