设置默认字体时,当尾风失败时?
如果我将通用选择器与Tailwind结合使用,那么并非所有元素都依靠默认值。我希望所有默认都会影响(如果尾风不加载/工作)。为了测试这一点,我删除了 @font-face规则和刷新显示影响字体。它似乎适用于大多数元素,但下面的DIV元素不起作用。下面的div仍然用于ARIAL默认值?这是因为我在DIV班级中设置了字体 - 核对中的媒体吗? 那么,如果尾风不加载/工作>,我该如何正确更改默认字体?另外,我正在使用Svelte框架。
更新:当我从DIV类中删除Font-NormsMedium时,它默认会影响我想要的是,但是当未从DIV类中删除它时,为什么它默认为Arial呢?
index.html
<style lang="postcss">
* {
font-family: Impact, sans-serif;
}
@font-face {
font-display: block;
font-family: NormsMedium;
src: url(path...)
format('woff2'),
url(path...)
format('woff');
font-weight: 400;
font-style: normal;
}
tailwind.config
module.exports = {
theme: {
extend: {
fontFamily: {
NormsBold: 'NormsBold',
NormsMedium: 'NormsMedium',
NormsRegular: 'NormsRegular',
},
},
}
元素不默认要影响
<div class="mt-1 mb-2 text-lg text-left font-NormsMedium line-clamp-2 ">90s Hair Now with Calista</div>
If I use a universal selector in conjunction with tailwind, not all the elements resort to default. I want everything to default to Impact (in case tailwind doesn't load/work). To test this, I remove the @font-face rule and refresh which shows the impact font. It seems to work for most elements, but not the div element below. The div below still goes to the arial default? Is this because i have font-NormsMedium set in the div's class? So How do I change my default font properly, in case tailwind doesn't load/work? Also, I am using svelte framework.
Update: When I remove font-NormsMedium from the div class it defaults to impact which is what I want, but why does it default to Arial when it is not removed from the div class?
INDEX.HTML
<style lang="postcss">
* {
font-family: Impact, sans-serif;
}
@font-face {
font-display: block;
font-family: NormsMedium;
src: url(path...)
format('woff2'),
url(path...)
format('woff');
font-weight: 400;
font-style: normal;
}
TAILWIND.CONFIG
module.exports = {
theme: {
extend: {
fontFamily: {
NormsBold: 'NormsBold',
NormsMedium: 'NormsMedium',
NormsRegular: 'NormsRegular',
},
},
}
ELEMENT DOES NOT DEFAULT TO IMPACT
<div class="mt-1 mb-2 text-lg text-left font-NormsMedium line-clamp-2 ">90s Hair Now with Calista</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果尾风失败,则“影响”将是默认值。您将添加到标记中的尾风课无效。但是您描述的情况是不同的:您看到的是字体未能加载的结果。
您的字体家庭规则是由尾风应用的,“撞击”,但没有指定的字体,因此使用后备。字体堆栈使您可以确定该后备应是什么。
如果您希望所有内容默认为“影响”,如果您的主字体未加载,请将其添加到字体堆栈中。
还值得正确设置您的
字体face
规则,以便它们都是一个具有按预期的权重的字体自己的。示例:
配置:
If Tailwind were to fail, "Impact" would be the default. The Tailwind classes you're adding to your markup would have no effect. The situation you're describing however is different: what you're seeing is the result of a font failing to load.
Your font-family rule is being applied by Tailwind, overriding "Impact" but the specified font isn't available so it uses a fallback. Font stacks allow you to determine what that fallback should be.
If you want everything to default to "Impact" if your primary font doesn't load, add it to your font stack.
It's also worth setting up your
font-face
rules correctly so that they're all one font family with the weights working as intended.Example:
Config: