Tech Note: Replacing Images

Charles Johnsonfollow me on twitter
Science • Wed Dec 31, 2008 at 5:36 pm PST • Views: 188

We’re improving the infrastructure around here again. One visible change is the disappearance of the little blue word balloon icon (), that showed up next to the number of comments at the bottom right of each front page article; it was redundant, because clicking the number of comments went to the same place, so the icon got the axe.

Bye, little blue word balloon. We’ll miss you.

Another change is that the remaining icons in that row now have “rollover” states, meaning that when your mouse cursor passes over them they change color subtly.

One major change you can’t see is the way that row of icons is constructed, but it’s kind of interesting from a techie standpoint, so we’ll explain it and those of you not interested in the nuts and bolts can skip ahead to what will inevitably become an open thread.

Previously, those icons were simple PNG images. The new structure uses an unordered list, combined with the Phark image replacement technique to display the icons as background images instead of <img> tags. This method is more accessible to screen readers, and also lets us achieve that rollover effect through pure CSS, without any Javascript.

Here’s a simplified version of what the list looks like in HTML:

The CSS code removes the bullet style from the unordered list, and floats the list to the right. The list items are all floated left, so they appear horizontally instead of the default vertical arrangement. A 4-pixel margin is added to create some space between the icons.

The links themselves are set to a fixed width and height, their display type is set to ‘block’, then the text inside them is moved off screen by setting the text-indent property to negative 10000 pixels. The background-repeat and background-position properties for all the links are set.

Then we can set the background images for the links, like so:

From an accessibility standpoint, this is an improvement; screen readers don’t pay attention to CSS, so they will see (and read) the text inside the links, while standard browsers will show the background image and no text.

The rollover effects are achieved with a nifty trick that uses only one image. Here’s the complete PNG file for the email icon, to show how it’s done:

email

Notice that both image states are combined into one file. Since the width of the links was explicitly defined as 16 pixels, we’re only going to see 16 pixels of the image at a time when it’s used as the background. And we can change to the rollover state simply by changing the background-position of the image, like so:

This instantly slides the image 20 pixels to the left (because the second image in our combined file begins 20 pixels from the left), so the rollover image now shows in that little 16 pixel area.

Image rollovers and increased accessibility, without a single line of Javascript — but wait, there’s more! The other big advantage of this technique: by using background images for this repeating element (the row of icons appears at the bottom of every front page post) instead of image files, there are far fewer calls to the server to display the page.

We’re now in the planning stages for converting the comment icons (that appear at the top right of each comment) to a similar system, which could result in a big improvement in the loading time of pages with lots of comments. And we know you’re as excited about that as Stinky and I am.

Advertisement

254 comments

^ back to top ^

Name:

Pass:

Register Forgot Your Password? Re-send Confirmation (To log in, cookies must be enabled in your browser!)

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...


► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form

More Partners

Compare Electricity Prices in your area. Texas Electricity is deregulated; you have the right to choose Texas Electric Rates from among many Texas Electric Companies.

Nobody would have the idea.

TwitterFacebook
LGF Pages
Recent Pages

I AM BREITBART!
Church Cheers as 4-Year-Old Sings 'Ain't No Homos Gonna Make It to Heaven'
4 minutes ago
Views: 21 • Comments: 2
Tweets: 1 • Rating: 1

Channeling Confucius
From the previous Diamond Jubilee: Kipling's 'Recessional'
28 minutes ago
Views: 16 • Comments: 0
Tweets: 0 • Rating: 0

Daniel Ballard
Egyptian Student Invents New Propulsion Method - Science - Health & Science - OnIslam.net
1 hour, 21 minutes ago
Views: 49 • Comments: 0
Tweets: 0 • Rating: 2

Bob Dillon
REVEALED: Hundreds of Words to Avoid Using Online if You Don't Want the Government Spying on You
1 hour, 33 minutes ago
Views: 36 • Comments: 0
Tweets: 0 • Rating: 0

Learned Mother of Zion
Native Americans Have Jewish DNA!
1 hour, 53 minutes ago
Views: 123 • Comments: 2
Tweets: 1 • Rating: 3

Eclectic Infidel
Mitt Romney for a better Amercia!
1 hour, 57 minutes ago
Views: 78 • Comments: 1
Tweets: 0 • Rating: 0

Aigle
Ha'aretz, Lost in Translation
5 hours, 12 minutes ago
Views: 126 • Comments: 3
Tweets: 0 • Rating: 0

Randall Gross
Government Employment Drops Under Obama, but Media Run With Romney Myth Anyway
7 hours, 2 minutes ago
Views: 177 • Comments: 0
Tweets: 6 • Rating: 2

researchok
French Philosopher Alain Badiou on the Real Expression of Love: 'If You Limit Yourself to Sexual Pleasure It's Narcissistic'
11 hours, 7 minutes ago
Views: 109 • Comments: 0
Tweets: 0 • Rating: 1

Aziz Poonawalla
I Speak for Myself: All-American
18 hours, 52 minutes ago
Views: 154 • Comments: 0
Tweets: 0 • Rating: 7

 Frank says:

Lord have mercy on the people in England for the terrible food these people must eat. And Lord have mercy on the fate of this movie and God bless the mind of the man in the street.