css - 如何使用 Styled-Components 设置全局字体系列
问题描述
我想设置font-family
全局使用Styled-Components
. 我使用createGlobalStyle
并将字体设置为正文,但正文中的 div 没有继承字体。
这是我的 Styled-components 正文:
import {createGlobalStyle} from 'styled-components';
export const AppRoot = createGlobalStyle`
body {
@import url('../../font.css');
font-family: Vazir !important;
direction: rtl;
text-align: right;
cursor: default;
}
`;
这是我使用它的方式:
import {AppRoot} from './StyledComponents';
ReactDOM.render (
<Fragment>
<AppRoot/>
<App />
</Fragment>,
document.getElementById ('root')
);
解决方案
我认为您可以使用*
selector 而不是body
.
export default createGlobalStyle`
* {
@import url('../../font.css');
font-family: Vazir !important;
// CSS you want global.
}
`
我用它来创建一个重置 css 来删除一些浏览器的规则。
推荐阅读
- c# - IronPdf HTML 页脚不会占据整个宽度
- python - 当 pyinstaller 与 --noconsole 一起使用时,Flask 应用程序未运行
- winapi - 如果队列中已经有东西,PeekMessage 是否永远不会生成新的 WM_TIMER 消息,无论过滤器如何?
- c# - 如何从 jwt 令牌登录用户并设置角色 .net core 2.2
- sequelize.js - TypeError models.User.find 不是函数
- r - 如何使用 SF 包进行空间联合,然后按几何图形分组?
- powershell - PowerShell 设置-AzureADApplication 权限
- typescript - Typescript 安全地实现类型相关的功能
- laravel - 如何在重新启动时发送超过 24 小时的未决通知?
- ruby-on-rails-5 - 在 Rails 5 belongs_to 中,我如何忽略 id 并通过唯一名称创建 accociation?