Use CSS for icons instead of <img> tags

davegan - September 17, 2008 - 16:07
Project:Service links
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Pretty simple request.. instead of using image tags in the css, it would be better to include a style sheet with the module.

That way, if you want to change the images, you can just overrule the css settings, not have to replace the images in the module itself.

#1

jrguitar21 - January 9, 2009 - 18:43
Status:active» needs review

I'm trying to optimize my Drupal site as much as possible using Yslow. This was a standard optimization that I was going to submit anyway, but found this issue... so i'll upload here.

I used the free online CSS sprite generator service http://spritegen.website-performance.org to create the sprites. **

The instructions for implementing (out of the box):

  1. unzip the attached tar to the drupal root: this will extract two new files to your service_links folder (the css and the sprites file).***
  2. apply the patch***

Customized sprites:

If you have implemented any of your own additional links and images, you need to:

  1. make sure the links are added to the custom section of the module code
  2. zip up the images,
  3. upload them to http://spritegen.website-performance.org/,
  4. Use the following CSS Output Options:
    • Horizontal offset: 16px
    • Vertical offset: 16px
    • Wrap columns: YES (checked)
    • Background Color: (leave blank)
    • Use Background Colour for Transparency: YES (checked)
    • Output format: GIF!!!
    • (Leave the rest as defaults)
  5. download the generated sprite
  6. overwrite the generated css into the service_links.css file. NOTE: dont copy and paste the #container li, but use the new file name (csg-XXXXXXXXXXXXX.gif) as a reference for the following...
  7. change the line in css that references the existing one:

    .share_service_links a {
    background-image: url(csg-495ea35a8db92.gif); /** change this sprite url **/

** Sorry but the zip includes an extra sprite for MySpace that is technically not covered by the regular 5.x version, you can find another patch around here to get the myspace link added to your set of service_links.

*** NOTE the patch assumes you've installed the module in sites/all/modules/service_links

AttachmentSize
service_links_css_sprites.tar_.gz 5 KB

#2

Rob Loach - March 19, 2009 - 21:24
Status:needs review» postponed

Might be a good thing to think about with #380322: Refactoring Service Links, but I don't think CSS Sprites is the way to do it, as adding additional images would require editing the CSS sprites image itself.

#3

TheCrow - March 20, 2009 - 16:37

If the question is "change the images without overwrite the originals" we can think to manage various subfolders under images/

#4

kmonty - April 24, 2009 - 10:06

I personally think this is a good idea for the core service links. Additional images/services can just be called by its own file.

#5

TheCrow - April 24, 2009 - 17:49

CSS sprite model added in refactoring plain!
Anyway the sprites will be generated automatically without any external website help.

#6

andrewsuth - September 18, 2009 - 03:09
Version:5.x-1.1» 6.x-2.x-dev
Status:postponed» active

I think generating the png image with all of sprites would be fantastic, and obviously the ideal situation - but I also think it will be a lot more work to code.

I just fear that this excellent feature will go down the same path as CSS Sprites which never made it out of DEV, 18 months ago. In fact, this kind of functionality I think belongs in it's own module, as it's functionality is applicable to many other modules.

Why not look for an easier solution to use in the meantime: like allowing for a "CSS Sprite" option to be selected, where you can then give the path to your image with all of the sprites (which you generate yourself). Then have fields for each of the service link icons to be manually assign it it'sbackground-position and sprite dimensions? I think this solution will be a lot easier to code and will more likely make it into the module.

I'm really interested in this feature, as being able to save 10 HTTP requests on each page load would be very user friendly..

UPDATE: I have 2 places where I show the Service Links on some pages, at the top and at the bottom. Because the module is using <img> markup for the images, the browser attempts to fetch each image twice. I can't wait for the CSS improvements to be done because my front-end load time is being slowed down by about 2 seconds for some users.

#7

andrewsuth - September 17, 2009 - 11:02

Here's an interesting link regarding automating CSS Sprites, probably the best attempt I have found yet. It's open source (under the Apache 2.0 license) and is in active development.

http://code.google.com/p/spriteme/

It generates the CSS image, does all of the positioning calculations and then gives you a live preview on the page you are currently viewing!

Go through the slideshow for more details: http://spriteme.org/demo.php

 
 

Drupal is a registered trademark of Dries Buytaert.