首页 > 其他分享 >(美化)WordPress网站添加自定义字体

(美化)WordPress网站添加自定义字体

时间:2022-10-30 12:31:06浏览次数:81  
标签:family 自定义 字体 https WordPress font com TsangerYuYangT 美化

背景

通过CSS属性@font-face和font-family可以实现加载自定义web font,改变网页字体,实现美化效果。

(美化)WordPress网站添加自定义字体_css

1.引用字体文件

出于版权风险考虑,尽量使用免费可商用的字体作为web font。

本文教程使用的为站酷仓耳渔阳字体,是站酷发布的免费可商用字体。

字体下载地址:https://www.zcool.com.cn/special/zcoolyytfonts

需要通过@font-face属性引用web font。

引用实例:

@font-face {
font-display: swap;
font-family: 'afengblogfont';
src: url('https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.woff2') format('woff2');
url('https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.woff') format('woff');
url("https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.eot");
url("https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.eot?#iefix") format('embedded-opentype'),
}

属性详解:

font-display  swap属性可以实现在web font未加载完成前使用浏览器默认字体渲染文本,当web font加载成功后再替换自定义字体,避免出现网页文本空白现象,影响用户阅读及体验。

font-family属性在此可以自定义web font的名称,以便在其他css样式中引用该名称,如此处使用的名称为:afengblog

src需要填写web font url,可以引用多个字体文件,但需要通过format定义该字体的格式,以便在多种浏览器中兼容,如:woff woff2 ttf

2.设置元素字体

引用完字体文件后需要通过font-family属性定义该元素的字体,如下示例:

html {
font-family: "afengblogfont", sans-serif;
font-weight: 400;
font-style: normal;
}

font-family属性填写引用字体文件设置的font-family属性名称

最终示例:

@font-face {
font-display: swap;
font-family: 'afengblogfont';
src: url('https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.woff2') format('woff2');
url('https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.woff') format('woff');
url("https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.eot");
url("https://libs.afengim.com/font/typeface/file/TsangerYuYangT/TsangerYuYangT-W03.eot?#iefix") format('embedded-opentype'),
}

html {
font-family: "afengblogfont", sans-serif;
font-weight: 400;
font-style: normal;
}

WordPress可以添加至主题根目录style.css文件的开头或添加到 外观>自定义>额外CSS内,无需添加style标签。

原文地址:​https://www.afengblog.com/wordpress-custom-fonts.html​

标签:family,自定义,字体,https,WordPress,font,com,TsangerYuYangT,美化
From: https://blog.51cto.com/u_15840885/5807502

相关文章

  • wordpress网站主题安装教程
    前面已经搭建好了网站,但是默认的页面比较简陋,我们需要更改一下外观现在我们安装新的主题外观,使网站更加的好看下载主题https://www.lovestu.com/corepress-free可以使......
  • Vue3——自定义组件-插件
    Vue3自定义指令插件官网链接:https://cn.vuejs.org/guide/reusability/custom-directives.html#introduce1.自定义指令:1.1自定义指令声明局部声明:constfocus={......
  • 博客园美化教程
    开始由于博客园的主题都是很久以前的,所以在现在看来不是非常好看。因此需要我们自己去优化一下教程自定义CSS首先我们在博客后台将主题切换成SimpleMemary,接着勾选......
  • antd的update组件自定义上传样式及列表样式
    项目需求按UI设计上传的样式需要把showUploadList={false},自己写上传列表//本次上传的文件const[fileList,setFileList]=useState([]);//初始化时存储之前上传......
  • Vue的自定义组件
    Vue的自定义组件自定义组件的作用是为了提高复用性,减少重复的代码,提高可维护性全局组件语法:vue.component("自定义组件名称",{自定义组件结构})vue.component("自......
  • 自定义jar包的使用
    1.先生成或者下载jar包到本地lib文件夹2.通过命令把jar包加到本地maven仓库命令把jar包加到本地maven仓库mvninstall:install-file-Dfile=ctg-ag-sdk-core-2.5.0-20220......
  • DOM第四章tab切换和自定义属性节点操作
    tab切换和自定义属性京东tab栏切换<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge">......
  • c#Winform自定义控件-信号灯(工业)-HZHControls UCSignalLamp 使用
     想要官网这个效果,自己琢磨了下,记录一下   一、拖一个UCSignalLamp控件   二、设置指示灯的属性//设置指示灯颜色(不闪烁只用写一个......
  • 如何不改动 GatewayWorker 依赖包下自定义协议
    前言:     GatewayWorker是Workerman的一个框架,对应用层开发者更友好。GatewayWorker多了一个网关,也就是Gateway,负责与客户端连接,消息转发等。而自定义的协......
  • 【Vue2.0学习】—Todolist案例自定义事件(六十)
    【Vue2.0学习】—Todolist案例自定义事件(六十)......