Font awesome icons 2.3 - categories, nodes, prefixes, phrases, templates etc...

Font awesome icons 2.3 - categories, nodes, prefixes, phrases, templates etc...

Mr Lucky

Well-known member
Mr Lucky submitted a new resource:

Font awesome icons 2.3 - A general guide to using Font Awesome icons in xenforo 2.3

Introduction​

There are two main situations where you might use font awesome (or other ) icons.

Pseudo elements (before &/or after text)​

In this case you specify via CSS code that an icon appears before or after some text, e.g. a node title, prefix, or navigation item. This is usually done by adding some CSS code to the extra.less template.

For css pseudo elements (icon before/after text) use this format of code in extra.less...

Read more about this resource...
 
Great resource, questions about Font Awesome icons are recurring, we can direct members to this resource. 🙏

For reference I also offer this link:


@Mr Lucky it would have been visually comfortable to use the appropriate code blocks for each syntax, Less and HTML to name a few.
Furthermore, even if .m-faContent works correctly, as your resource only concerns XF 2.3 therefore the recommended syntax is rather .m-faIcon for what concerns Font Awesome icons. But using the .m-faContent syntax allows compatibility with XF 2.2...
 
About this:
Note that as well as inline CSS (as above style="...") you can alternatively define a class to use in your CSS (in template extra.less)
<xf:fa class="your-class" icon="fad fa-sparkles" aria-hidden="true" />

I usually add classes to FA icons this way:
HTML:
<xf:fa icon="fad fa-sparkless my-class" />

// even two classes

<xf:fa icon="fad fa-sparkless my-class another-class" />

it works very well.
I don't know if it's "academic" but it works, maybe @Jeremy P could confirm that it doesn't possibly cause problems later, elsewhere...
 
I would recommend using the class attribute for classes and the icon attribute for selecting an icon.

Not that we have imminent plans to break this, but relying on unintentional behavior is always liable to cause compatibility issues in the long-term.
 
@Mr Lucky it would have been visually comfortable to use the appropriate code blocks for each syntax, Less and HTML to name a few.
Thanks done that, though I'm not sure it's appropriate to call <xf:fa icon="fal fa-sparkles" aria-hidden="true"/> html :unsure:
 
Last edited:
Thanks for this @Mr Lucky :)

Do you happen to know how you would specify primary and secondary colors when calling a duotone icon via CSS? class="fa-secondary" doesn't seem to get added unless the icon is added via <xf:fa icon="fa-music">. I'm trying to add duotone icons to group banners but I can't seem to figure this out. I asked here also but no response yet.
 
I didn't try but something like that maybe:
Less:
.custom--duotone {
    color: var(--fa-primary-color, #000);
    color: var(--fa-secondary-color, #fff);
}
HTML:
<xf:fa icon="fad fa-user" class="custom-duotone" />
 
I didn't try but something like that maybe:
Less:
.custom--duotone {
    color: var(--fa-primary-color, #000);
    color: var(--fa-secondary-color, #fff);
}
HTML:
<xf:fa icon="fad fa-user" class="custom-duotone" />

No luck, but I appreciate the attempt :)
 
Of course, i'm dumb, in any case the second color property override the first one...
Maybe a clue here:
 
Less:
.your-icon
{
    transform: rotate(180deg); // rotation

    color: #000; // color

    .fa-secondary
    {
        color: #FFF; // secondary color (duotone)
    }
}
 
Less:
.your-icon
{
    transform: rotate(180deg); // rotation

    color: #000; // color

    .fa-secondary
    {
        color: #FFF; // secondary color (duotone)
    }
}

Unfortunately this doesn't seem to work with icons added via CSS (.m-faContent(@fa-var-duotone-star);) rather than <xf:icon>.

@Chris D

How do you specify primary and secondary colors when calling a duotone icon via CSS? class="fa-secondary" doesn't seem to get added unless the icon is added via <xf:fa icon="fa-music">. I'm trying to add icons to group banners but I can't seem to figure this out.
 
Oh yeah, due to how CSS icons work it's not possible to customize their secondary color.
 
Ah bummer. So if I wanted to use duotone icons for userbanners I couldn't do so while using <xf:userbanner>, right?
 
You can, but you would only be able to customize the primary color if you're applying them with CSS. You can use the JS renderer instead to allow further customization:

HTML:
<i class="fad fa-alien your-icon" data-xf-init="icon"><svg></svg></i> Alien
 
Back
Top Bottom