最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - How does PrimeNG use classes to display icons instead of HTML tags? - Stack Overflow

programmeradmin1浏览0评论

I was reading through the GitHub project and noticed that icons extend from a BaseIcon class, which in turn extends from a BaseComponent. From what I saw, you can use the selector, for example, <AngleUpIcon>, to display the SVG of that icon. However, I would like to understand how PrimeNG manages to display icons using classes, for example:

<i class="pi pi-user" style="font-size: 2.5rem"></i>

Find a clear explanation of how PrimeNG achieves the functionality of displaying icons using classes instead of HTML tags, possibly through custom components or other mechanisms.

I was reading through the GitHub project and noticed that icons extend from a BaseIcon class, which in turn extends from a BaseComponent. From what I saw, you can use the selector, for example, <AngleUpIcon>, to display the SVG of that icon. However, I would like to understand how PrimeNG manages to display icons using classes, for example:

<i class="pi pi-user" style="font-size: 2.5rem"></i>

Find a clear explanation of how PrimeNG achieves the functionality of displaying icons using classes instead of HTML tags, possibly through custom components or other mechanisms.

Share Improve this question edited Mar 18 at 8:15 DarkBee 15.5k8 gold badges72 silver badges117 bronze badges asked Mar 18 at 7:02 José AlvaradoJosé Alvarado 111 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

https://github/primefaces/primeicons/blob/master/primeicons.css — this is the explanation you're looking for.

Basically, they use PrimeIcons, which are anized as a font. .pi CSS class specifies that it should use this font, and adds some rendering hints:

.pi {
    font-family: 'primeicons';
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    display: inline-block;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

While the specific class, e.g. .pi-user, simply specifies which symbol to render before your empty element:

.pi-user:before {
    content: "\e939";
}

This char code corresponds to the necessary icon in the font.

Obviously, having the whole icon set as a single file reduces the number of HTTP requests, which is the primary reason to anize it that way.

发布评论

评论列表(0)

  1. 暂无评论