| item | desc |
|---|---|
| font-family | 字体家族;通常为一个系列 英文优先;先写英文字体,再写中文字体 |
| font-size | 字体大小 |
| font-weight | 字体重量/加粗;关键字,如light 300、normal 400、bold 600;推荐使用数字 100 - 900 |
| font | 以上3个属性的复合写法 |
| color | 字体颜色 |
| line-height | 行高;通常指定1.5倍行高,易于阅读;PC端通常指定为字体大小+8px的行高;可用于单行文本的垂直方向居中 |
| letter-spacing | 字符间距;通常使用em单位;对中文有效 |
| word-spacing | 字间距;通常使用em单位;适用于英文,对中文影响较小 |
| hyphens | 对英文来说,添加连字符的方式,一般选择auto,更为紧密 |
| text-indent | 文本缩进;通常为2em |
| text-align | 文本对齐:默认left;right | center | justify |
| text-align-last | 末尾文本对齐方式;特别适合单行时,字符个数不同时的两端对齐 |
| text-transform | 文字变化,首字大写 capitalize | 大写 uppercase | 小写 lowercase;适用于英文 |
| text-decoration | 线条修饰:下划线 underline、上划线 overline、删除线 line-through;<del>也可以实现删除效果 |
| text-overflow | 文字溢出处理 |
| white-space | 空白字符处理,换号、不换行等 |
| vertical-align | 行内文本对齐方式:baseline | middle | top | bottom |
| writing-mode | 文字方向,如古文的从右到左 vertical-rl |
| text-shadow | 文字阴影,默认是文字颜色;可以多次叠加,以逗号,区分;更多阴影使用,请访问 盒阴影、滤镜 |
| text-stroke | 文字描边颜色和宽度;部分浏览器不支持;建议使用 SVG 实现 |
font-family: "Alibaba PuHuiTi", "Source Han Serif", "Source Han Sans", "PingFang SC", "Microsoft YaHei", "微软雅黑", Arial, Helvetica, sans-serif;
text-shadow: h-shadow v-shadow blur color;
-webkit-text-stroke: length color;
a,
input,
button {
font: inherit;
color: inherit;
}
.outer {
background: #596673;
color: #b7bfc8;
text-shadow: 0 -2px 2px #000;
}
.inner {
background: #8c99a6;
color: #434d56;
text-shadow: 0 2px 2px #fff2;
}
.txt-stroke {
text-align: center;
font-size: 60px;
font-family: 'yuwei';
color: transparent;
-webkit-text-stroke: 1px #fff;
line-height: 120px;
text-shadow: 0 0 10px #ff0;
background-image: url(../imgs/section.jpg);
}
@font-face {
font-family: font_name;
src: url(font_url);
font-weight: normal;
font-style: normal;
font-display: swap;/*先默认字体显式,当字体加载完毕再切换*/
}
@import url('sample.css');
<link rel="stylesheet" href="sample.css" />
body {
font-family: font_name;
}
@font-face {
font-family: 'Poppins';
src: url(../fonts/Poppins/Poppins-light.ttf);
font-weight: 300;
font-display: swap;
}
@font-face {
font-family: 'Poppins';
src: url(../fonts/Poppins/Poppins-Regular.ttf);
font-weight: 400;
font-display: swap;
}
@font-face {
font-family: 'Poppins';
src: url(../fonts/Poppins/Poppins-Bold.ttf);
font-weight: 600;
font-display: swap;
}
//定义
@font-face {
font-family: "YuWei";
src: url('../fonts/YuWei/YuWeiShuFaXingShuJianTi.ttf')
font-display: swap;
}
//使用
.core {
text-align: center;
font-family: "YuWei";
font-size: 2.5rem;
color: #eb2f06;
outline: #fff;
font-weight: 700;
text-shadow:
2px 0px 0px #fff,
0px 2px 0px #fff,
-2px 0px 0px #fff,
0px -2px 0px #fff,
4px 4px 8px #333;
}