如何更改<button>元素的font-family?

bry*_*yan 4 html css fonts

这是我唯一的CSS

@font-face {
  font-family: 'thefont';
  src: url('fonts/the-font.otf');
  font-style: normal;
}

body {
    font-family: 'thefont';
}
Run Code Online (Sandbox Code Playgroud)

当我做一个<button>Hi</button>字体最终成为-apple-system.

如果我实际分配了字体button,它将使字体出现.

有谁知道它为什么不影响身体及其内部的一切?

Geo*_*nos 7

除了下面的信息,为了确保按钮考虑您的自定义字体,您需要申请

button {
    font-family : inherit;
    font-size: 1em;
}
Run Code Online (Sandbox Code Playgroud)

所有按钮元素.

你可以在那里检查他们是如何做到的:

http://purecss.io/buttons/

或者那里:

http://getbootstrap.com/css/#buttons

还要确保以多种不同格式导出字体,以便所有平台都支持它.

您可以使用FontSquirrel Generator将字体导出为所有格式.

你的CSS应该看起来像这样:

@font-face {
  font-family: 'thefont';
  src: url('the-font.eot'); /* IE9 Compat Modes */
  src: url('the-font.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('the-font.woff2') format('woff2'), /* Super Modern Browsers */
       url('the-font.woff') format('woff'), /* Pretty Modern Browsers */
       url('the-font.ttf')  format('truetype'), /* Safari, Android, iOS */
       url('the-font.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Run Code Online (Sandbox Code Playgroud)