字体css制作
字体 CSS 制作方法
设置字体类型
使用 font-family 属性指定字体,可以设置多个字体作为备选,用逗号分隔:
p {
font-family: "Arial", "Helvetica", sans-serif;
}
调整字体大小
通过 font-size 属性控制文字尺寸,支持像素(px)、em、rem等单位:
h1 {
font-size: 2em;
}
控制字体粗细
使用 font-weight 定义文字粗细,数值范围100-900或关键词(normal/bold):
strong {
font-weight: 700;
}
设置字体样式
font-style 属性可设为 italic(斜体)或 oblique(倾斜):
em {
font-style: italic;
}
调整字符间距
letter-spacing 控制字母间距,可为正值或负值:
.title {
letter-spacing: 1px;
}
自定义字体
通过 @font-face 引入外部字体文件:
@font-face {
font-family: 'CustomFont';
src: url('font.woff2') format('woff2');
}
body {
font-family: 'CustomFont';
}
行高控制
line-height 调整行间距,建议使用无单位数值(如1.5):
article {
line-height: 1.6;
}
文本装饰效果
text-decoration 可添加下划线、删除线等效果:
a {
text-decoration: none;
}
字体颜色设置
使用 color 属性改变文字颜色,支持各种颜色表示法:
.warning {
color: #ff0000;
}
字体平滑处理
font-smoothing 可改善字体在非Retina屏幕的显示效果(WebKit/Gecko私有属性):
body {
-webkit-font-smoothing: antialiased;
}






