How to reference external CSS files and iconfont in WeChat applet wxss

How to reference external CSS files and iconfont in WeChat applet wxss

cause

The way to import external files into a mini program is: @import "*/*.wxss";

Due to business needs, iconfont needs to be used in the small program being developed, and it is easy to think of the introduction method of H5:

````
@font-face {font-family: "iconfont";
 src: url('iconfont.eot?t=1485242349767'); /* IE9*/
 src: url('iconfont.eot?t=1485242349767#iefix') format('embedded-opentype'), /* IE6-IE8 */
 url('iconfont.woff?t=1485242349767') format('woff'), /* chrome, firefox */
 url('iconfont.ttf?t=1485242349767') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
 url('iconfont.svg?t=1485242349767#iconfont') format('svg'); /* iOS 4.1- */
}

.iconfont {
 font-family:"iconfont" !important;
 font-size:16px;
 font-style:normal;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
}

````

Because this CSS style is universal, it is placed in lib/style/font.wxss. The file directory is as follows:

It is introduced into the required file through @import, but it has no effect.

Reason: The font-face URL of the wxss file of the applet does not accept the http address as a parameter, but can accept base64. Therefore, you can first download the font file, convert it to base64, and then reference it.

The solution is as follows:

1. First, go to Alibaba vector icon library (http://iconfont.cn/) to generate your own font icon, download it, and find the ttf format file

2. Go to this platform https://transfonter.org/ and convert the font file into base64 format

3. Introduce in lib file

4. Add fonts to wxss

5. Display Effect

Summarize

This is the end of this article about how WeChat mini program wxss references external CSS files and iconfont. For more relevant content about mini program wxss referencing external files, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of how to import wxml, wxss, and js into a WeChat applet
  • WeChat applet implements wxss attribute example of operating wxml through js
  • Use wxss to load pictures and realize animation effects in WeChat applet
  • Implement support for wxml and wxss files of WeChat applet in webstrom
  • How to compile WeChat applet less files into wxss files
  • WeChat Mini Program Tutorial: WXSS
  • WeChat Mini Program WXML, WXSS and JS Introduction and Detailed Explanation
  • WeChat Mini Program WXSS Style File Tutorial

<<:  The difference between MySQL execute, executeUpdate and executeQuery

>>:  Detailed graphic tutorial on silent installation of oracle12.2 on CentOS under VMware

Recommend

MySQL 5.7.17 installation and configuration graphic tutorial

The blogger said : I have been writing a series o...

Vue implements various ideas for detecting sensitive word filtering components

Table of contents Written in front Requirements A...

Detailed explanation of mysql permissions and indexes

mysql permissions and indexes The highest user of...

Detailed explanation of HTML basics (Part 2)

1. List The list ul container is loaded with a fo...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

Vue implements sending emoticons in chat box

The specific code for sending emoticons in the vu...

Detailed explanation of the TARGET attribute of the HTML hyperlink tag A

The hyperlink <a> tag represents a link poin...

Vue Element-ui form validation rule implementation

Table of contents 1. Introduction 2. Entry mode o...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...

Solve the problem of ifconfig being unavailable in docker

Recently, when I was learning docker, I found tha...

How to get datetime data in mysql, followed by .0

The data type of MySQL is datetime. The data stor...

Mysql queries the transactions being executed and how to wait for locks

Use navicat to test and learn: First use set auto...

A detailed explanation of the subtle differences between Readonly and Disabled

Readonly and Disabled both prevent users from chan...

How to implement online hot migration of KVM virtual machines (picture and text)

1. KVM virtual machine migration method and issue...

When should a website place ads?

I recently discussed "advertising" with...