
Yep, you didn’t read it wrongly – the javascript which Flick gave you to insert your personalised Flickr badge is indeed buggy! It just happened over the afternoon – the Flickr badge JS has some new modifications which will potentially affect the layout of your blog.
The crux of the problem
If you have the script, look into the source of the script. The follow is the badge code for my script, after following Veerle’s simple steps of converting the code to make it XHTML valid:
<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=4&display=random&size=s&layout=x&source=user&user=44742295%40N00">
Highlight everything between the inverted commas after src=, then copy + paste it to your address bar. You should arrive at a page which displays something like this:
var b_txt = '<img src="http://geo.yahoo.com/p?s=792600102&t=ad64ee1b82b556e2adac6caee93c4ae5&fl_ev=0〈=en&intl=sg" width="0" height="0" alt="" />';
// write the badge
document.write(b_txt)
//document.write(b_txt.split('< ').join('<'))
You will notice that Flickr Badge JS has sneakily appended the HTML code of including an empty gif at the start of your Flickr badge. And to my horror, the addition of that innocent-looking transparent gif screwed up the design of the main page of my blog.
Distorted layout

Image displacement is observed.
As you can see from the image to the right, the usual styling I’ve applied to my Flickr images has caused the transparent gif to affect the position of the rest of the images such that the last one is pushed off the container. I’ve set a definite height and overflow: hidden to the container such that content overflows will not affect the rest of the content.
The little blue square at the top right hand corner is the cause of the problem – since I’ve set the width of the container such that the images fit snugly into it, any additional space will cause the images to be pushed to the subsequent row. Thus in the screenshot, the second image (that photo of a shrimp salad) which should appear on the first line was pushed to the second row. This causes the last image to be positioned way off the fixed dimensions of the container.
Workaround #1 – Excluding the transparent gif
If you’d scrutinise the irritating image the Flickr badge JS has inserted in, you will realise that while other displayed Flickr photos will be wrapped around the link tag:
<a href="ImagePageURL" title="ImageDesc"><img src="ImageURL" title="ImageDesc"></a>
… while the miserable little pain-in-the-ass transparent gif is just an unlinked image. The unlinked image is where this first workaround is taking advantage of. My old CSS styling for the images were (simplified for presentation purposes):
div#flickr img {border: 4px solid #a4b6d2;float: left;margin: 0 4px 4px 0;padding: 0;}div#flickr img:hover {border: 4px solid #ffffff;}
The problem is immediately clear – I’m assigning a 4px border to the transparent gif too! This will create an 12px wide unnecessary space (4px for left border, 4px for right border and 4px for the margin), thus pushing the second, fourth, sixth and etc to the next row. To circumvent the problem:
Method 1: You’ll just need to change your code such that the border only targets linked images (since the transparent 1x1px gif is not linked).
div#flickr a img {border: 4px solid #a4b6d2;float: left;margin: 0 4px 4px 0;padding: 0;}div#flickr a img:hover {border: 4px solid #ffffff;}
Method 2: Alternatively, if you’re reluctant to use the ‘border’ attribute but wishes to add borders to your images, Veerle‘s has got a neat workaround for it. I’ve used the concept behind her workaround and modified it a little for personal use:
div#flickr a img {background: #a4b6d2;float: left;margin: 0 4px 4px 0;padding: 4px;width: 75px;height: 75px;}div#flickr a img:hover {background: #ffffff;}
Her method is to pre-define the size of the image, then assign a fixed padding to them and then define the background colour. This creates borders around the images. The img:hover property is a pseudo-class – whenever you hover your cursor over that image the background changes colour.
*Disadvantage of Method 1 and Method 2 (both are under Workaround #1): This is merely a stop-gap measure – this means that if Flickr ever does edit their sneaky Flickr badge javascript, you might need to think of an alternative workaround. For example, if Flickr links the transparent gif, this workaround will not work. This brings us to the second fix.
Workaround #2 – Targeting the transparent gif
Another workaround will be directly targeting transparent gif by stopping the browser from displaying properly. This workaround is kindly provided by tomodea.
div#flickr img[src*="http://geo.yahoo.com"] {display: none;}
This fix is painless and easy :) what you’re doing if you place this in your stylesheet is that you’ll be instructing the browser not to display images from http://geo.yahoo.com, which is where the transparent gif is hosted at.
*Disadvantage of Workaround #2: If Flickr changes the image URL, you’ll have to modify the image source. More importantly, if Flickr switches the image source to a php file which randomly picks transparent gif from various place (which is unlikely unless Flickr is ought to be evil), this fix will not work.
Fixed!

Problem corrected with CSS (:
After applying any of the methods describe above, your problem will be fixed for the moment being. The screenshot to the right shows the product of the three fixes – since they basically do the same thing, there’s no point posting three separate screenshots.
I’ve tested the three methods on my blog in various browsers – Firefox 3, Safari 3, Opera 9 Google Chrome 0.2 and IE 7. All fixes seem to work fine, but I cannot guarantee there’s no problem for people using IE6 and below – and if you’re still using IE6, please upgrade to IE7 as it’s for free (even if you’re using a pirated copy of Windows). There’s simply no reason hanging your dear life onto IE6.
For the moment being, the size of the transparent gif is set to height=0px and width=0px, if you do look at the badge script. I hope the Flickr team wouldn’t mess with the dimensions or life will be hell for us :razz:
If you have any questions or problem with the fixes, or have any cooler CSS workarounds, feel free to post them in your comment! Thanks!



















Hello! Had the same exact problem, and today my flickr badge was all misaligned, just like yours… I fixed changing my css so that it puts border and padding to the images that are links only as in your suggestion #1 . What I was wondering was what the heck is that thing they put in there? :(
Alices last blog post..One more wordpress site
Hey Alice, I’m glad that the fixed worked for you! It took me an hour to figure out where the problem lies (at first I thought it was because I set the number of photos to 4, which is not part of the options provided by Flickr badge – they gave options of 1, 3 or 5 photos). I suspect that the transparent gif that is inserted into the badge is for tracking purposes, i.e. the level of usage of a user’s Flickr badge or something. But they should’ve informed us about the changes instead of doing it so abruptly that made many people crack their brains over it.
You’re my hero, Teddy!
Brandys last blog post..*pinch* for a new month.
Brandy, thank you soooo much for the generous plug in your Plurk :mrgreen: and I’m glad that the fix worked for you too!
Fix for buggy Flickr badge JS…
Flickr changed their Flickr badge JS unexpected yesterday, which involves appending a blank transparent gif to the start of the badge. The change, seemingly small, will wreck havoc in your template if not fixed. I’ve posted 3 easy and painless fixes…
This should definitely help a lot of people!
The whole change didn’t really affect my layout…I wasn’t even aware of the change.
The whole code that they give you actually looks really weird to me…I dunno…maybe it’s just me.
Hope you’re having a great day Teddy :-)
I hope it does, Amarilys! Anyway, I’m glad that the change did not affect your layout – perhaps you’ve got the correct styling before the sneaky Flickr team altered the code. The whole code they gave me wasn’t the javascript one – they gave me the <script>…</script> stuff, and I just copied the source, pasted the source URL in my browser to check what’s wrong with their JS ;)
cheeem stuff which i will never decipher(: no wonder my blog is still a new blog!!
hahaahh!! whee
Chongxs last blog post..3rd Sept
Whatever Chongx :D or I can give you tutorials on CSS and XHTML muahaha! But as if the C++ you’re taking now isn’t overwhelming enough :razz: lol! Good luck!
[...] code. Why fix something that looked fine? There’s a CSS fix. Teddy wrote a tutorial here. Of course, Failbook had to jump into the same bandwagon, and change their layout – which I hate [...]
Thanks Teddy!
Thank you! This helped me a lot. I’ve used the Workaround #2 (adapting it to my css) and it works like a charm!
Workaround #2 worked perfectly for me. Thank you!
Jenns last blog post..webhostingrating.com