Practical operation of using any font in a web page with demonstration

Practical operation of using any font in a web page with demonstration

I have done some research on "embedding non-system built-in fonts in web pages" before. Although it is technically feasible, it does not have much practical significance in China, because a Chinese font file is at least 20M+, and the font files supported by each browser are different. In other words, there must be 2-3 font files of different formats on the server side to cope with each browser. You can see the corresponding picture below.

I thought this little research I did before would not be useful in my future work, but it turned out to be useful. A customer requested to display the time, but the font of the time must be the same as that of a digital watch, as shown in the figure:

First of all, we need to find this font. Since this font is only in ttf format, we need to convert it into various other formats. As for how to convert, there are software and online. I will not specify which one to use here.

After the conversion, you can write the CSS code

Copy code
The code is as follows:

@font-face {
font-family: 'hooray'; /*Name your custom font*/
src: url('http://demo.jb51.net/js/2013/webfontry/hooray.eot');
src: url('http://demo.jb51.net/js/2013/webfontry/hooray.eot?#iefix') format('eot'),
url('http://demo.jb51.net/js/2013/webfontry/hooray.woff') format('woff'),
url('http://demo.jb51.net/js/2013/webfontry/hooray.ttf') format('truetype'),
url('http://demo.jb51.net/js/2013/webfontry/hooray.svg#webfontjKg17VrE') format('svg');
}

As for the call, just like usual, define font-family where needed, and the font name is the name just named:

Copy code
The code is as follows:

font-family: 'hooray';

Download the complete demo. Online Demo

I did not explain the reasons for many things in the article, because there is a lot of information on the Internet about "using arbitrary fonts on web pages", but there are few examples. If you don't understand something, just go to Baidu or Google and you will understand.

Appendix 1: Two new online font conversion websites are added: FontsQuirrel and onlinefontconverter.

<<:  A brief discussion on how to solve the depends_on order problem in Docker-compose

>>:  MySQL learning: five major constraints of database tables explained in detail for beginners

Recommend

Detailed explanation of the process of modifying Nginx files in centos7 docker

1. Install nginx in docker: It is very simple to ...

W3C Tutorial (16): Other W3C Activities

This section provides an overview of some other i...

How to check if data exists before inserting in mysql

Business scenario: The visitor's visit status...

CSS sets Overflow to hide the scroll bar while allowing scrolling

CSS sets Overflow to hide the scroll bar while al...

Detailed usage of Vue more filter widget

This article example shares the implementation me...

Example of how to configure multiple virtual hosts in nginx

It is very convenient to configure virtual host v...

Windows 10 1903 error 0xc0000135 solution [recommended]

Windows 10 1903 is the latest version of the Wind...

A brief analysis of mysql index

A database index is a data structure whose purpos...

Vue realizes price calendar effect

This article example shares the specific code of ...

Implementation of modifying configuration files in Docker container

1. Enter the container docker run [option] image ...

Detailed explanation of Linux zabbix agent deployment and configuration methods

1. Install zabbix-agent on web01 Deploy zabbix wa...

Shell script to monitor MySQL master-slave status

Share a Shell script under Linux to monitor the m...

One line of code solves various IE compatibility issues (IE6-IE10)

x-ua-compatible is used to specify the model for ...

Solution to the problem that the mysql8.0.11 client cannot log in

This article shares with you the solution to the ...