Trying to use css to insert png icons in tag boxes

Hello, I am trying to use a set of png icons for icons on my forum on the tags. iv got it to fit in the tag box how it looks nice but that’s for every tags box, iv found how to target specific tags but what would be the right way of selecting that specific tag box to put in the png icon? Any help would be awesome!

trying to select one -

.tag-question::before {
    content: url(https://s2.coinmarketcap.com/static/img/coins/16x16/1.png);
    width: 8px;
    height: 4px;
    margin-right: 10px;
    margin-top: 3px;
    display:inline-block;
}

Selecting all -

a.discourse-tag.box::before {
    content: url(https://s2.coinmarketcap.com/static/img/coins/16x16/1.png);
    width: 8px;
    height: 4px;
    margin-right: 10px;
    margin-top: 3px;
    display:inline-block;
}

Why not use SVG glyphs instead of PNGs? There’s a component for this at Tag icons component

I was already trying that but with what I am trying to do I would need to try and convert like 400+ png icons to svg and then make all of that an svg sprite and from what iv tried and read there isn’t a fast or good way of converting them and keeping the quality of the original png. I did try with one icon a few times but the quality would usually go down and then when I put it into a sprite I couldn’t get it to load with the theme component.

You can use css attribute selector

Here is an example with the tag question :

a.discourse-tag.box[href*="question"]::before {

With 400 tags you might need to use something else than the [href*= for some elements. There are a few alternatives to trigger the attribute element.

https://www.w3schools.com/css/css_attribute_selectors.asp

4 Likes

ah, ty! :grinning: this should work great with what I am trying to do.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.