MyBB Tutorials

Forum Icons with a CSS Spritesheet Image

Submitted by Aoki, , Thread ID: 21021

Thread Closed
Aoki
retired
Level:
83
Reputation:
348
Posts:
7.89K
Likes:
2.3K
Credits:
1.7K
10-05-2016, 02:17 AM
#1
This was requested by devil.
I'm showing you how to make your forum icons using a spritesheet image.



1. Why would you use this?

Quote:An image sprite is a collection of images put into a single image. A web page with many images can take a long time to load and generates multiple server requests.
Using image sprites will reduce the number of server requests and save bandwidth.



2. Generate your spritesheet

Simply go to this site: https://draeton.github.io/stitches/

The first thing you want to do is adding your icons.

[Image: BIrhT.png]

After you've added your icons, they should appear in this spritesheet demo:

[Image: s5WfB.png]

On the right side we have settings. Just copy my settings and you're fine. It's important to name the prefix "ficons", otherwise you need a different CSS code.

[Image: 2Qtkw.png]

After you've done this, click on the top download button and save your spritesheet image.

[Image: ihxET.png]

Upload this image via FTP to your image directory of your MyBB installation. (yourdomain.com/images/spritesheet.png)

Do not close this page yet. We will need it again!



3. Add CSS

On the same download page, click on the CSS tab and copy everything to your global.css file. (AdminCP > Templates & Style > Themes > Your Theme > global.css)

This should look similar to this:

Code:
.ficons {
  background-image: url(spritesheet.png);
  background-repeat: no-repeat;
  display: block;
}

.ficons-1 {
  width: 24px;
  height: 24px;
  background-position: -1px -1px;
}

.ficons-2 {
  width: 24px;
  height: 24px;
  background-position: -27px -1px;
}

.ficons-3 {
  width: 24px;
  height: 24px;
  background-position: -1px -27px;
}

Now we want to set the proper image path. Edit:

Code:
background-image: url(spritesheet.png);

to:

Code:
background-image: url(images/spritesheet.png);

Here comes the tricky part. All your icons are using different CSS classes now. Example: ficons-1, ficons-2 and ficons-3.
The numbers are actually the Forum ID's of your forums. You need to give each icon the proper class with the proper Forum ID, otherwise they won't be displayed correctly.

How to find out the Forum ID of a forum:

Navigate to AdminCP > Forums & Posts and click on any forum. You'll now see the Forum ID in the URL of your page.

[Image: YBSlb.png]



4. Editing Templates

Remember to make a backup of everything in case you're doing something wrong.

Navigate to AdminCP > Templates & Style > Templates > Your Theme Templates > Forum Bit Templates > forumbit_depth2_forum
Look for this line:

Code:
<span class="forum_status forum_{$lightbulb['folder']} ajax_mark_read" title="{$lightbulb['altonoff']}" id="mark_read_{$forum['fid']}"></span>

And replace it with:

Code:
<i class="ficons ficons-{$forum['fid']} ajax_mark_read" title="{$lightbulb['altonoff']}" id="mark_read_{$forum['fid']}"></i>



That's basically it. If you have any questions, feel free to ask.
1

RE: Forum Icons with a CSS Spritesheet Image

Kawaii
Novice
Level:
0
Reputation:
4
Posts:
22
Likes:
0
Credits:
31
12-05-2016, 11:02 PM
#2
Looks like your image host has died, might be worth re-uploading.

RE: Forum Icons with a CSS Spritesheet Image

Aoki
retired
Level:
83
Reputation:
348
Posts:
7.89K
Likes:
2.3K
Credits:
1.7K
OP
12-05-2016, 11:10 PM
#3
12-05-2016, 11:02 PM
Kawaii Wrote:
Looks like your image host has died, might be worth re-uploading.

Nope, works fine.

RE: Forum Icons with a CSS Spritesheet Image

meh
Oh! Didn't See Ya There.
Supreme
Level:
0
Reputation:
54
Posts:
926
Likes:
103
Credits:
1.19K
12-05-2016, 11:20 PM
#4
12-05-2016, 11:02 PM
Kawaii Wrote:
Looks like your image host has died, might be worth re-uploading.

Triple check to make sure that the network you're on isn't blocking it, it works fine for me.

[Image: hgkiag.png]

RE: Forum Icons with a CSS Spritesheet Image

Kawaii
Novice
Level:
0
Reputation:
4
Posts:
22
Likes:
0
Credits:
31
13-05-2016, 01:46 PM
#5
12-05-2016, 11:10 PM
Aoki Wrote:
Nope, works fine.

Yup, my mistake, Malwarebytes firewalled the site.

RE: Forum Icons with a CSS Spritesheet Image

JumpingJack
Member
Level:
0
Reputation:
9
Posts:
141
Likes:
6
Credits:
6
13-05-2016, 03:24 PM
#6
Any tutorial for making stylsheet for awards as shown here?

RE: Forum Icons with a CSS Spritesheet Image

MichaudĀ©
Novice
Level:
0
Reputation:
0
Posts:
25
Likes:
1
Credits:
33
13-05-2016, 06:34 PM
#7
This is awesome, was wondering how to do this, since I guess this is what you have to do when editing post icons

RE: Forum Icons with a CSS Spritesheet Image

Aoki
retired
Level:
83
Reputation:
348
Posts:
7.89K
Likes:
2.3K
Credits:
1.7K
OP
13-05-2016, 06:50 PM
#8
13-05-2016, 03:24 PM
Medishared Wrote:
Any tutorial for making stylsheet for awards as shown here?

It's not as simple as this unless you make a new page seperate from the one which is used by the plugin.

RE: Forum Icons with a CSS Spritesheet Image

ferax7
Lurker
Level:
0
Reputation:
0
Posts:
5
Likes:
0
Credits:
6
24-08-2016, 06:26 PM
#9
I did not know how to do it lol I liked the tutorial very well explained

RE: Forum Icons with a CSS Spritesheet Image

ash7890
Member
Level:
0
Reputation:
0
Posts:
106
Likes:
1
Credits:
0
05-11-2016, 11:33 PM
#10
A nice way to do it without a plugin. Thanks for this Smile

Users browsing this thread: 1 Guest(s)