Detailed explanation of how to introduce custom fonts (font-face) in CSS

Detailed explanation of how to introduce custom fonts (font-face) in CSS

Why did I use this? It all started with the making of the poster. It was a stormy night. . .

Okay, let’s stop talking nonsense and get back to the topic. Why do we use it? Because the browser doesn’t have the font.

Then why should you tell me? I myself won’t go to w3cschool to read and learn. Yes, but wouldn't it be quicker and easier if I could provide you with

How to use

@font-face{
     font-family: 'You can name the font at will'; 
     src: url('../font/font name.eot');
     src:url('../font/font name.woff') format('woff'),
         url('../font/font name.ttf') format('truetype'),
         url('../font/font name.svg') format('svg');
}

//Add an h1 or other text in the HTML code, and write the special text you want inside it h1{font-size:36px; color:#ccc;font-family: "font name is up to you";}

It ends here. Thank you for watching (Hey, can you please stop throwing eggs and breaking cabbages? I’ll continue talking);

1. Where to find the font is the key. I know how to use it but it’s useless without the font. .

Font download: https://www.jb51.net/fonts/

Here you can find the fonts generally supported by our system and download them and put them in the font folder (the font folder can be at the same level as css and images)

2. The downloaded font is too large, which results in poor performance (otherwise there are many problems)

Solution: Zizhu (It can extract the required part of the font, which is usually only a few KB, so it should be OK)

Font Spider official website: http://font-spider.org/

1) If you want to use Zizhu, you must first install node or git, which is fine as a front-end;

2) After installation, start installing font-spider. Use the command line or git to copy this sentence: npm install font-spider -g You can also use Taobao mirror

3) After a long wait, we can first test font-spider -V after the installation is complete. Seeing the version number proves that you have installed it successfully, Nice.

4) Remember to put the multi-megabyte fonts you downloaded into the font folder we just mentioned.

5) Create a new CSS style sheet, define the font, copy the following into it, and enter the font name you just named in font. In this way, all the formats of the font are defined.

@font-face{
     font-family: 'You can name the font at will'; 
     src: url('../font/font name.eot');
     src:url('../font/font name.woff') format('woff'),
         url('../font/font name.ttf') format('truetype'),
         url('../font/font name.svg') format('svg');
}

//Add an h1 or other text in the HTML code, and write the special text you want inside it h1{font-size:36px; color:#ccc;font-family: "font name is up to you";}

6) The key step is to generate the abbreviations you need. Enter font-spider+space+path in git or node: font-spider ./demo/*.html

for example:

If the disk is in the root directory, you can directly use font-spider demo.html

or

font-spider C:\Users\13246\Desktop\cropper\demo.html

Of course, I am demonstrating this, so the specific path depends on your computer.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Linux disk space release problem summary

>>:  A brief discussion on JS regular RegExp object

Recommend

React Native environment installation process

react-native installation process 1.npx react-nat...

MySQL full-text search Chinese solution and example code

MySQL full text search Chinese solution Recently,...

Implementation example of uploading multiple attachments in Vue

Table of contents Preface Core code File shows pa...

Binary installation of mysql 5.7.23 under CentOS7

The installation information on the Internet is u...

JS achieves five-star praise effect

Use JS to implement object-oriented methods to ac...

Enabling or disabling GTID mode in MySQL online

Table of contents Basic Overview Enable GTID onli...

Methods of adaptive web design (good access experience on mobile phones)

1. Add the viewport tag to the HTML header. At th...

How to deploy Spring Boot using Docker

The development of Docker technology provides a m...

MySQL tutorial data definition language DDL example detailed explanation

Table of contents 1. Introduction to the basic fu...

The rel attribute of the HTML link tag

The <link> tag defines the relationship bet...

Node implements search box for fuzzy query

This article example shares the specific code for...

How to use MySQL limit and solve the problem of large paging

Preface In daily development, when we use MySQL t...

The basic principles and detailed usage of viewport

1. Overview of viewport Mobile browsers usually r...

HTML Tutorial: Collection of commonly used HTML tags (4)

Related articles: Beginners learn some HTML tags ...

The implementation process of Linux process network traffic statistics

Preface Linux has corresponding open source tools...