Get yourself a great looking Twtitter badge

Twitter has absolutely exploded over the past few months, it’s all over the radio and TV; even some ‘celebrities’ can’t get enough of Twitter - yes I am refferring to Ashton Kutcher.

With a lot of social experiments like this you need and should want to make it your own, by using a custom Twitter badge. Of course you can already customise your background on Twitter among other things, but what can you do about it outside of the birds nest? Once again CSS (bless those CSS gods up there) is on our side and as the ground work of Twitter is essentially one big list <ul><li></li></ul> it’s dead easy to style up.

Let start with a basic Twitter badge and explanation of the custom CSS

This is what we’re going to create.

First we need the worm, or Twitter’s script to get your feed working. The correct place for this is really your <head> but I find the best place is to stick it just before your end </body> tag. I suggest this because for one, the script is coming from a remote site (though you could make it local if you wish) and having it at the bottom of the page will allow the rest of your more important content to load first. Anyway, lets get started and add this in to our page.

HTML

Be sure to take note of src in the second included bit of script. You’ll need to replace BenjaminReid with your own username and change count=5 to the amount of tweets you would like to show on your page.

<script src="http://twitter.com/javascripts/blogger.js" type="text/javascript"><!--mce:0--></script>
 
<script src="http://twitter.com/statuses/user_timeline/BenjaminReid.json?callback=twitterCallback2&amp;count=5" type="text/javascript"><!--mce:1--></script>

The only other bit you need to get it working is the layout HTML below, which is also provided by Twitter.

HTML

<div id="twitter_div">
 
	<ul id="twitter_update_list">
 
 
	</ul>
 
</div><!-- /twitter_div -->

If you’re ever doing this for a client and they can only see the source of your page, instead of the full generated source and they want the page to validate just add <li></li> to the list.

CSS

Now for the magic. Add this into your stylesheet and watch it transform. I’ll explain it line by line below.

#twitter_div { width: 300px; padding: 10px; background-color: #410323; border: solid 1px #5E0F38; }
 
ul#twitter_update_list { width: 300px; padding: 0; margin: 0; overflow: hidden; }
 
ul#twitter_update_list li { width: 300px; padding: 5px 0 5px 0; border-bottom: solid 1px #680441; list-style: none; }
 
ul#twitter_update_list li a { color: #FFFFFF; border-bottom: dotted 1px; text-decoration: none; }
 
ul#twitter_update_list li a:hover { color: #CA0A6C; border-bottom: solid 1px; }

First let’s just look at each element that’s in play. Just reference the colours below to the boxes in the diagram to see what’s going on.

#twitter_div
ul#twitter_update_list
ul#twitter_update_list li
ul#twitter_update_list li a

Basic layout of the badge

#twitter_div

The <div> that contains the Twitter is given deep background colour that will stand out off the <body>’s dark grey background and a sharp one pixel border to create a nice contrast. It’s also got ten pixels of padding to keep the list from butting up against the edges.

CSS

#twitter_div { width: 300px; padding: 10px; background-color: #410323; border: solid 1px #5E0F38; }

ul#twitter_update_list

The main list also given a width just for protection, the padding and margin’s have been taken removed to stop the default indentation and the overflow is set to hidden so that we stop something like IE6 kicking out.

CSS

ul#twitter_update_list { width: 300px; padding: 0; margin: 0; overflow: hidden; }

ul#twitter_update_list li

Each list item has had the bullet points removed as they don’t look to great in this case, some padding to spread each item out and a border just to define the end of each one that little more.

CSS

ul#twitter_update_list li { width: 300px; padding: 5px 0 5px 0; border-bottom: solid 1px #680441; list-style: none; }

ul#twitter_update_list li a

The <a> tags are styled up as per the rest of my site with a dotted white border which then joins into a solid pink when rolled over.

CSS

ul#twitter_update_list li a { color: #FFFFFF; border-bottom: dotted 1px; text-decoration: none; }
 
ul#twitter_update_list li a:hover { color: #CA0A6C; border-bottom: solid 1px; }

This should now give you the basic knowledge to style the badge up how you want. I’m going to style up one more and add a little jQuery to highlight each Tweet when’s it’s rolled over.

The sleek jQuery badge

This is the badge, shiny ‘ey?

I’ve modified the CSS slightly but the main importance is the addition of the nice lookin’ but simple jQuery.

This will just change the background colours of each individual <li> depending on which on is being rolled.

JavaScript

$(document).ready(function(){		
 
	$('ul#twitter_update_list li').mouseover(function(){
 
		$(this).css({'background-color' : '#b1b1b1'});
 
	});	
 
	$('ul#twitter_update_list li').mouseout(function(){
 
		$(this).css({'background-color' : '#d5d5d5'});
 
	});				
 
});

Author: Nouveller

My name is Benjamin Reid, I live in the UK and keep the magic locked into this site.

RSS Icon

Subscribe to the RSS feed some design goodness, get in on the upcoming software give-aways!

Digg Icon Share Get yourself a great looking custom Twitter badge to Twitter Share Get yourself a great looking custom Twitter badge to Delicious Share Get yourself a great looking custom Twitter badge to Facebook

Related post(s)

Comments left by other wizards

16 Responses | Make a comment

Leave your words of wisdom

Leave a Reply

This is a Gravatar

Your name