javascript - 全局字体系列不适用于按钮
问题描述
我使用 styled-components 以下列方式创建一个按钮和一个链接组件
import { Link } from "react-router-dom";
import styled, { css } from "styled-components";
const style = css`
text-decoration:none;
font-size:2rem;
border-radius:10px;
color:var(--white);
background-color:transparent;
border: none;
cursor: pointer;
padding:1.25rem 3rem;
text-transform:uppercase;
letter-spacing:.15rem;
&:hover,
&:active {
color:var(--colorFour);
}
`
export const StyledButton = styled.button`${style}`
export const StyledLink = styled(Link)`${style}`
我的项目中也有一个全局样式,它设置了一个全局字体系列
body {
font-family: 'Comic Neue', sans-serif;
height:100vh;
padding:0 2rem;
display:flex;
justify-content:center;
align-items:center;
background: var(---colorOne);
background: linear-gradient(to right, var(--colorTwo), var(--colorOne));
}
'Comic Neue'
当我使用链接组件时,应用了正确的样式
但是,如果我使用按钮,则应用样式是出于某种原因-apple-system
奇怪的是,当我查看按钮的计算样式时,它看起来'Comic Neue'
应该适用,但由于某种原因它不适用
有谁知道可能是什么问题?
解决方案
表单元素不继承该font-family
属性。
将font-family: inherit
CSS 属性添加到按钮以使用与正文相同的字体。
button {
font-family: inherit;
}
推荐阅读
- reactjs - 如何在 React js Web 应用程序的页面导航中更改 Material UI ToolBar 中的标题?
- python - 十进制/二进制转换器无法转换二进制
- laravel - 如何在同一个视图中运行多个 Livewire 组件(无嵌套)
- google-app-engine - AppEngine Flex 是否支持运行时 .NET 5
- typescript - 如何在 TypeScript 枚举中使用属性键 (object.key)?
- r - 替换R中一个单元格上的日期值
- ruby-on-rails - 导致遗留问题的路线轨道 5,不能破坏等
- php - 如何在 Laravel 8.x 的视图中检索 cookie 值?
- python - 停止语句执行直到为真
- python - 如何从接口外部访问变量