html字体样式代码大全

在HTML中,你可以使用CSS来定义字体样式。设置字体类型:

html
<style> body { font-family: Arial, sans-serif; /* 优先使用Arial字体,如果不可用则使用sans-serif字体 */ } </style>

设置字体大小:

html
<style> p { font-size: 16px; /* 设置段落字体大小为16像素 */ } </style>

设置字体颜色:

html
<style> h1 { color: #333; /* 使用十六进制颜色值设置标题颜色 */ } </style>

设置字体样式:

html
<style> em { font-style: italic; /* 设置斜体 */ } strong { font-weight: bold; /* 设置粗体 */ } </style>

设置行高:

html
<style> p { line-height: 1.5; /* 设置段落行高为1.5倍字体大小 */ } </style>

文本对齐:

html
<style> h2 { text-align: center; /* 将标题居中对齐 */ } </style>

文本装饰:

html
<style> a { text-decoration: underline; /* 设置链接下划线 */ } del { text-decoration: line-through; /* 设置删除线 */ } </style>

字体变换:

html
<style> .uppercase { text-transform: uppercase; /* 将文本转换为大写 */ } .lowercase { text-transform: lowercase; /* 将文本转换为小写 */ } .capitalize { text-transform: capitalize; /* 将每个单词的首字母转换为大写 */ } </style>

html
<style> @font-face { font-family: 'CustomFont'; src: url('path/to/custom-font.woff2') format('woff2'), url('path/to/custom-font.woff') format('woff'); /* 指定字体文件的路径和格式 */ font-weight: normal; font-style: normal; } body { font-family: 'CustomFont', sans-serif; /* 使用自定义字体,如果不可用则回退到sans-serif */ } </style>

请确保替换path/to/custom-font.woff2path/to/custom-font.woff为实际字体文件的路径,并根据需要调整字体的名称。这样,你就可以在网页上使用自定义字体了。

对于更复杂的排版需求,你可能需要深入学习CSS和Typography方面的知识,以充分发挥CSS在字体样式设计方面的强大功能。希望这些示例能帮助你开始设置基本的字体样式。