search
HomeWeb Front-endH5 TutorialMethod steps (code) for IconFont icon reference

Method steps (code) for IconFont icon reference

Sep 13, 2018 pm 05:40 PM
html5javascript

The content of this article is about the method steps (code) of IconFont icon reference. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Front-end development will often use some icons. When the icons provided by ui girl cannot meet your needs, you can collect and generate your own business icon library on iconfont.cn and then use it.

1. Generate icon library code

First, search and find the icon you need, collect it into your shopping cart, in the shopping cart, you can add the selected icon Go to the project (if it doesn't exist, create a new one), and the subsequent resources/code generated

will be based on the project dimension.

Method steps (code) for IconFont icon reference

Go to the project page you just selected and click the link "Generate Code". Codes for different introduction methods will be generated below. introduce.

Method steps (code) for IconFont icon reference

2. Import

There are three import methods for you to choose from: SVG Symbol, Unicode and Font class. We recommend using SVG Symbol to import in modern browsers.

SVG Symbol

The introduction of SVG symbols is the mainstream icon introduction method for modern browsers in the future. The method is to preload symbols, introduce them where appropriate and render them as vector graphics. It has the following features:

  1. Supports multi-color icons and is no longer limited by single-color icons

  2. Through some techniques, it supports, like fonts, Adjust the style through font-size and color

  3. Supports IE 9 and modern browsers

The steps are as follows:

  • Switch to the Symbol tab and copy the address code generated by the project:

//at.alicdn.com/t/font_835630_0rudypqb4a.js
  • Add the icon style code. If there are no special requirements, you You can directly reuse the style of the Ant Design icon

.icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: -.125em;
}
  • Select the corresponding icon and get the class name, and apply it to the page

<svg>
    <use></use>
</svg>

You can also use the Icon.createFromIconfontCN({...}) method provided by the Ant Design icon component to use icons more conveniently. The usage method is as follows:

  • Configure the project address , after creating the icon component

import { Icon } from 'antd';

const IconFont = Icon.createFromIconfontCN({
  scriptUrl: '//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.js'
});

export default IconFont;
  • , it can be used as conveniently as using the component, and supports configuration styles

<iconfont></iconfont>

Unicode

This is the most original way, which requires three steps to complete the introduction:

  • Copy the font library code generated by the project, you can create a new one Style files to place icon-related styles.

@font-face {
  font-family: 'iconfont';
  src: url('//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.eot');
  src: url('//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.eot?#iefix') format('embedded-opentype'),
  url('//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.woff') format('woff'),
  url('//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.ttf') format('truetype'),
  url('//at.alicdn.com/t/font_405362_lyhvoky9rc7ynwmi.svg#iconfont') format('svg');
}
  • Add the icon style code. If there are no special requirements, you can directly reuse the Ant Design icon style.

.iconfont {
  display: inline-block;
  font-style: normal;
  vertical-align: baseline;
  text-align: center;
  text-transform: none;
  line-height: 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  &:before {
    display: block;
    font-family: "iconfont" !important;  /* 注意与 font-face 中的匹配 */
  }
}
  • Move the mouse to the icon you want to use in the project, click "Copy Code", and you will get the font encoding corresponding to the icon, which can now be imported directly Now:

<i></i>

Font Class

  • Switch to the Font class tab and introduce the following generated css code at the head of the page:

//at.alicdn.com/t/font_835630_0rudypqb4a.css
If you don’t like the way tags are introduced, you can also directly copy the code in the link above into your style file. If you don’t like the class name generated by the website by default, you can rewrite this part of the code yourself, for example:
 - .icon-ali-pay:before { content: "\e66b"; }              // 修改前
 - .monitor-icon-alipay:before { content: "\e66b"; }       // 修改后
  • At this time, you can choose to copy the code corresponding to the icon (which is the class name. If the class name is rewritten I have written it before, remember to use the modified one here), use it directly:

<i></i>

However, we recommend encapsulating it:

import React from 'react';

const BizIcon = (props) => {
  const { type } = props;
  return <i></i>;
};
export default BizIcon;

Now it can be used more conveniently:

<bizicon></bizicon>

Unicode and Font Class are essentially fonts. You can control the display of this icon through some font style attributes. At the same time, browser compatibility is very good, but multi-color icons are not supported.

Related recommendations:

iconfont-Use of vector icon font_html/css_WEB-ITnose

iconfont font icon and Detailed explanation of various css small icons

The above is the detailed content of Method steps (code) for IconFont icon reference. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the H5 tag in HTML?What is the H5 tag in HTML?May 09, 2025 am 12:11 AM

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

H5 Code: A Beginner's Guide to Web StructureH5 Code: A Beginner's Guide to Web StructureMay 08, 2025 am 12:15 AM

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

H5 Code Structure: Organizing Content for ReadabilityH5 Code Structure: Organizing Content for ReadabilityMay 07, 2025 am 12:06 AM

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

H5 vs. HTML5: Clarifying the Terminology and RelationshipH5 vs. HTML5: Clarifying the Terminology and RelationshipMay 05, 2025 am 12:02 AM

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

HTML5 Features: The Core of H5HTML5 Features: The Core of H5May 04, 2025 am 12:05 AM

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

H5: Exploring the Latest Version of HTMLH5: Exploring the Latest Version of HTMLMay 03, 2025 am 12:14 AM

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Beyond Basics: Advanced Techniques in H5 CodeBeyond Basics: Advanced Techniques in H5 CodeMay 02, 2025 am 12:03 AM

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool