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

js implements the algorithm for specifying the order and amount of red envelopes

This article shares the specific code of js to im...

Detailed explanation of Nginx log customization and enabling log buffer

Preface If you want to count the source of websit...

Tutorial on installing mysql under centos7

Recently, I plan to deploy a cloud disk on my hom...

CSS Skills Collection - Classics among Classics

Remove the dotted box on the link Copy code The co...

Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

Preface Because the mini program upload requires ...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

Interaction in web design: A brief discussion on paging issues

Function: Jump to the previous page or the next p...

Solve the problem of Syn Flooding in MySQL database

Syn attack is the most common and most easily exp...

Front-end development must learn to understand HTML tags every day (1)

2.1 Semanticization makes your web pages better u...

Network configuration of Host Only+NAT mode under VirtualBox

The network configuration of Host Only+NAT mode u...

Detailed explanation of uniapp's global variable implementation

Preface This article summarizes some implementati...

Example analysis of the page splitting principle of MySQL clustered index

This article uses an example to illustrate the pa...

Solution to the problem of eight hours difference in MySQL insertion time

Solve the problem of eight hours time difference ...