Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: Allach on May 20, 2025, 05:28:36 PM

Title: Insert image before the link in navbar
Post by: Allach on May 20, 2025, 05:28:36 PM
I've added a new link that leads to my other website. I want to insert an image in front of it.How do I do that?
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 20, 2025, 05:53:16 PM
If you've created a new button in Subs.php, like this -


            'test' => array(
                'title' => 'Test',
                'href' => $scripturl . '?action=test',
                'show' => $context['allow_search'],
                'sub_buttons' => array(
                ),
            ),


You can add an image in index.css like this -


.main_icons.test::before {
    background-position: -31px -109px;
}


The main menu button images are loaded from -

  /Themes/default/images/icons/main_icons_sprite.png

You just have to get the coordinates right to select an image from the sprite.

Title: Re: Insert image before the link in navbar
Post by: Allach on May 21, 2025, 02:23:36 PM
I can't get an icon to appear in front of the link. I just can't get it to work. What am I doing wrong?
Title: Re: Insert image before the link in navbar
Post by: Illori on May 21, 2025, 03:35:21 PM
what have you done? without details on your side we cannot tell what may be doing wrong.
Title: Re: Insert image before the link in navbar
Post by: Allach on May 21, 2025, 04:47:40 PM
The icon should go before the Nova Villa link.

My site is:

https://nova-arcade.com/
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 21, 2025, 09:10:45 PM
The button code should like this in Subs.php -


'nova-villa' => array(
    'title' => 'Nova-Villa',
    'href' => 'https://nova-villa.de',
    'show' => true,
    'sub_buttons' => array(
    ),
),


You don't need any sub_buttons.

The image is added in index.css -


.main_icons.nova-villa::before {
    content: "";
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    background: url(https://nova-arcade.com/Themes/default/images/icons/arcade_games.png);
}



Looks like this, links to your phpBB forum -

   nova-villa_ss2.jpg

That's your arcade icon, you can replace it with a different one.


Title: Re: Insert image before the link in navbar
Post by: Allach on May 22, 2025, 02:18:32 PM
Still don't get an icon in front of Nova Villa.
Title: Re: Insert image before the link in navbar
Post by: Kindred on May 22, 2025, 02:22:19 PM
that error suggests that either you screwed up the code -- or your host is having problems. WHat does your server-side error log show?
Title: Re: Insert image before the link in navbar
Post by: Allach on May 22, 2025, 02:38:27 PM
The error message is gone now. It's working again. I followed the instructions and still no icon is displayed in front of Nova Villa.
Title: Re: Insert image before the link in navbar
Post by: Kindred on May 22, 2025, 04:38:39 PM
Clear your local cache.... it works find for me.

JUst went to your site and I see background: url(https://nova-arcade.com/Themes/ProCurve/images/icons/favicon4a.png); as the icon for that menu item
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 22, 2025, 04:54:52 PM
You've also messed up the placement of the image -


.main_icons.nova-villa::before {
    content: "";
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    background: url(https://nova-arcade.com/Themes/ProCurve/images/icons/favicon4a.png);
}


Should look like this -

   nova_ss3.jpg

Title: Re: Insert image before the link in navbar
Post by: Allach on May 23, 2025, 02:12:16 PM
Now it works. The only problem is that the icon is right next to the link. How can I change the distance to the link?
Title: Re: Insert image before the link in navbar
Post by: Kindred on May 23, 2025, 04:23:15 PM
Add padding right
Title: Re: Insert image before the link in navbar
Post by: Allach on May 23, 2025, 04:59:13 PM
I did that, but unfortunately without success.

Title: Re: Insert image before the link in navbar
Post by: Illori on May 23, 2025, 07:49:59 PM
you may need to disable css minification and/or clear your cache to see the change.
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 23, 2025, 10:21:45 PM
CSS is correct, padding doesn't help.  I can't reproduce that positioning. 

Disable 'Minimize CSS' in Features and Options.

Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 23, 2025, 10:40:16 PM
Well, the good news is I can reproduce the positioning in ProCurve theme.  :)

Bad news is, I can't fix it.  :(

Must be a conflict in the ProCurve css.  Maybe you can ask Twitch in theme support topic.
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 23, 2025, 11:13:16 PM

Ok, here's the conflict -


/* Font Awesome */
.main_icons, .icon {
    margin-inline-end: 0px;
//    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-family: "Font Awesome 6 Free";
}

.main_icons.nova-villa::before {
    content: "";
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    background: url(https://nova-arcade.com/Themes/ProCurve/images/icons/favicon4a.png);
}


When display: inline-flex; is removed, the nova-villa icon aligns correctly vertically.  Adding a space before 'title' in Subs.php moves it over a bit -


'nova-villa' => array(
    'title' => ' Nova-Villa',
    'href' => 'https://nova-villa.de',
    'show' => true,
    'sub_buttons' => array(
    ),
),


Removing inline-flex will probably break things elsewhere, you'd have to ask Twitch about that.  You can see it moves the other menu icons down a few px.

   nova_ss4.jpg

Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 23, 2025, 11:31:29 PM
Well, this works, not sure why -


/* Font Awesome */
.main_icons, .icon {
    margin-inline-end: 0px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-family: "Font Awesome 6 Free";
}
.main_icons.nova-villa {
    display: inline-block;
}
.main_icons.nova-villa::before {
    content: "";
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    background: url(https://nova-arcade.com/Themes/ProCurve/images/icons/favicon4a.png);
}


Don't forget to add the space in Subs.php.

Even a blind pig occasionally finds a mushroom.

Title: Re: Insert image before the link in navbar
Post by: Allach on May 26, 2025, 02:30:47 PM
Clearing the forum cache didn't help either.
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 26, 2025, 08:36:39 PM
Did you try the code in my previous post?  Have you disabled minified css?

The icon displays correctly at https://nova-arcade.com/, you just have to add a space before title to position it a little further left -


'nova-villa' => array(
    'title' => ' Nova-Villa',
    'href' => 'https://nova-villa.de',
    'show' => true,
    'sub_buttons' => array(
    ),
),


Title: Re: Insert image before the link in navbar
Post by: Allach on May 27, 2025, 11:39:27 AM
I tried everything and nothing helped.

Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 27, 2025, 04:48:03 PM
Vertical alignment is correct.  If you've added a space in 'title' and it doesn't work, try this -


    'title' => '&nbspNova-Villa',


Or you can try this -


.main_icons.nova-villa {
    display: inline-block;
    margin-right: 5px;
}

Title: Re: Insert image before the link in navbar
Post by: Allach on May 28, 2025, 10:34:29 AM
Now it worked. Thanks.
Title: Re: Insert image before the link in navbar
Post by: HITG on May 28, 2025, 11:11:13 AM
Quote from: Allach on May 20, 2025, 05:28:36 PMI've added a new link that leads to my other website. I want to insert an image in front of it.How do I do that?

How can I do this too like add links change links.
Title: Re: Insert image before the link in navbar
Post by: Sir Osis of Liver on May 28, 2025, 12:56:34 PM
Read this topic from beginning.