Skip to main content

CSS Font

默认字体

body {
/* 优先系统默认 */
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
}

body {
/* Sans-Serif */
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji';

/* Serif */
font-family: Iowan Old Style, Apple Garamond, Baskerville, Times New Roman, Droid Serif, Times, Source Serif Pro, serif,
Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;

/* Monospace */
font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}

中文

body {
/* mac 优先 苹方 windows 优先 雅黑 */
font-family: 'PingFang SC', 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Helvetica, Arial,
Verdana, sans-serif;
}

font-face

@font-face {
font-family: 'OpenSans';
/* full name, postscript name, fallback */
src: local('Open Sans'), local('Open Sans'), url('/fonts/OpenSans.woff');
}

@font-face {
font-family: 'Montserrat';
src: local('Montserrat'), url('/assets/fonts/Montserrat.ttf');
/* 字体支持多种 weight */
font-weight: 100 900;
}

字体 子集

字体单位如何选择

<meta name="viewport" content="width=device-width, initial-scale=1" />
let rem = 14;

if (width > 768) {
rem = 45;
} else if (width > 414) {
rem = 26;
} else if (width > 375) {
rem = 18;
} else if (width > 320) {
rem = 16;
}
html {
font-size: 16px;

@media screen and (min-width: 900px) {
font-size: 18px;
}

@media screen and (min-width: 1200px) {
font-size: 20px;
}
}