【发布时间】:2020-06-25 01:50:42
【问题描述】:
我在 index.css 中使用 font-face 并在我的应用程序的其他地方访问这些字体系列。
我的要求是将这些字体中的每一个分配给不同的变量。并在我的应用程序中使用这些变量。我想将这些变量一般命名为“常规”、“中等”,因为如果我将其从 OpenSans 更改为其他字体系列,我不需要在我的应用程序的其他部分将字体系列作为 OpenSans 更改为其他。
我正在使用styled-components 进行样式设置。
@font-face{
font-family: 'OpenSans';
font-style: normal;
font-weight: 400;
src: url(./assets/Fonts/OpenSans-Regular.ttf)
}
@font-face{
font-family:'OpenSans-SemiBold';
font-style: normal;
font-weight: 400;
src:url(./assets/Fonts/OpenSans-SemiBold.ttf)
}
@font-face{
font-family:'OpenSans-SemiBoldItalic';
font-style: normal;
font-weight: 400;
src:url(./assets/Fonts/OpenSans-SemiBoldItalic.ttf)
}
@font-face{
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 400;
src: url(./assets/Fonts/ProximaNova-Regular.ttf);
}
@font-face{
font-family: 'Proxima Nova Medium';
font-style: normal;
font-weight: 400;
src: url(./assets/Fonts/proxima-nova-medium.ttf);
}
此外,一旦将这些字体分配给不同的变量,我如何访问其他组件的样式组件 例如:
const p = styled.p`
font-family: ??? --> is it using ${variable_name} ?
`
我对 index.css 的要求:
var Medium-font = {
@font-face{
font-family: 'Proxima Nova Medium';
font-style: normal;
font-weight: 400;
src: url(./assets/Fonts/proxima-nova-medium.ttf);
}
};
var Regulat-font = {
@font-face{
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 400;
src: url(./assets/Fonts/ProximaNova-Regular.ttf);
}
};
and so on..
【问题讨论】:
-
我会在 SASS 中进行。你想把你的代码放在哪里?
-
@VictoriaRuiz 想把它放在我的应用的 index.css 中
-
如果 SASS 不是一个选项,使用这个:codeburst.io/…
-
各位,您在样式组件中内置了 SASS,尽量不要误导。
-
@VictoriaRuiz,如何将每个字体分配给不同的变量并包裹在 :root 选择器中
标签: css reactjs styled-components