可以别名一个字体家庭/体重吗?

发布于 2025-01-18 04:11:16 字数 208 浏览 4 评论 0原文

我正在一个项目中工作,其中字体系列被定义为内联样式,其中内置了加权细节,例如font-family:inter_700bold

是否有一种方法可以使CSS/HTML中的font中的别名。 -family:Inter_700bold变为font-fomily:inter,font-jight:700

I'm working in a project where font families are defined inline style with weighting detail built into them, like font-family: Inter_700Bold

Is there a way to alias that in css/html where font-family: Inter_700Bold becomes font-family: Inter,font-weight:700

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清眉祭 2025-01-25 04:11:16

一种可能的解决方案可能是要使用您提到的内联样式定位元素的选择器,并将重量/实际字体应用于它们。

[style*="font-family: Inter_700Bold"] {
  font-family: 'Inter_700';
  font-weight: 700;
}
<p style="font-family: Inter_700Bold;">has the font family</p>
<p style="text-transform: capitalize; font-family: Inter_700Bold;">has other styles as well</p>
<p>doesn't have the font family</p>

One possible solution could be to have a selector that targets elements by the inline style you mention, and apply the weight/actual font to them.

[style*="font-family: Inter_700Bold"] {
  font-family: 'Inter_700';
  font-weight: 700;
}
<p style="font-family: Inter_700Bold;">has the font family</p>
<p style="text-transform: capitalize; font-family: Inter_700Bold;">has other styles as well</p>
<p>doesn't have the font family</p>

罪#恶を代价 2025-01-25 04:11:16

您不能在HTML/CSS中使用某种动态别名,您将需要某种预处理程序。
但是,在定义@font-face时,您定义了字体的本地页面别名:

@font-face {
  font-family: 'this_font_will_be_used_through_this_long_ugly_name';
  ...
}
.some_element{
  font-family: this_font_will_be_used_through_this_long_ugly_name;
}

确保您需要将所有可能的组合定义为@font-face定义。

You can't use some sort of dynamic aliases in html/css, you gonna need some kind of preprocessor for that.
But while defining a @font-face, you define a local page alias for the font:

@font-face {
  font-family: 'this_font_will_be_used_through_this_long_ugly_name';
  ...
}
.some_element{
  font-family: this_font_will_be_used_through_this_long_ugly_name;
}

Sure you will need all possible combinations defined as such the @font-face definitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文