With the addition of a facebook fan box to your website you’re not only benefiting your end users but also yourself. The fb fan box allows users to directly view how many friends you have on your facebook page and also allows them to become a fan with just one click. The only potential downsides to adding a fan box to your page is that it is not easy to customize or the original styling just doesn’t match up with the unique style of your site. Well not anymore, in this tutorial we are going to teach you how to customize your very own facebook fan box.
This tutorial will teach you step by step how to customize your facebook fan box to look like ours. After completing this tutorial you should be able to play around with the code and make modifications that you see fit to change the styling to your own needs.
4/29/10 – This tutorial has been updated to allow full customization of the Facebook Fan Box and positioning of the new “Like” button.
Setting Up Your Widget
Step 1 – Get Your Facebook Fan Box Code
First things first you need to get the code for your facebook fan box from facebook, your code should look something similar to the code below.
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script> <script type="text/javascript">FB.init("1690883eb733618b294e98cb1dfba95a");</script> <fb:fan profile_id="34572893685" stream="0" connections="10" logobar="0" width="300"></fb:fan> <div style="font-size:8px; padding-left:10px"><a href="http://www.facebook.com/pages/North-Miami-FL/Daddy-Design/34572893685">Daddy Design</a> on Facebook</div>
![]()
Step 2 – Linking Your CSS
The second step is to set up the linking to your css code and adjusting your facebook fan box code to allow for the customization you’re about to start. The div associated at the end of the original fan box code is only a link back to your facebook page, we decided to remove it, however you may choose to leave it. Items that we have changed in our code are the width from 300 to 240 and connections from 10 to 8, your width and number of connections may change depending on the space available for your fan box. Items we have added are height at 200 (also subject to change) and the line of code to link to our css stylesheet. Please view the updated coded below.
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script> <script type="text/javascript">FB.init("1690883eb733618b294e98cb1dfba95a");</script> <fb:fan profile_id="34572893685" stream="0" connections="8" logobar="0" width="240" height="200" css="http://www.yoursite.com/stylesheet.css?1"></fb:fan>One important item to take notice of is ‘?1’ which appears at the end of the css link, this item is the cache level for the facebook fan box, every time you make changes to the css inside your stylesheet and upload to your server you must change the number after the question mark to correspond with the number of edits you have made.
Here’s another handy tip, if you are using wordpress you can insert your code to look like the code below, this will link straight to your wordpress stylesheet. (Make sure you edit the ‘?1′ accordingly.)
css="<?php bloginfo('stylesheet_url'); ?>?1"
Styling Your Widget with CSS
Step 1 – Styling the Main Widget
The first step in customizing the css is to fix link hover issues and to remove any unneeded styling from the main widget. Check the first set of css modifications below.
.fan_box a:hover{ text-decoration: none; } .fan_box .full_widget{ height: 200px; border: 0 !important; background: none !important; position: relative; }In lines 1 through 3 of the code we have removed the underline hover effect for all links inside the fan box to avoid any type of conflicts. In lines 4 through 9 of the code we have removed the border from around the full fan box widget, set the height to match our widget height, removed the background, and positioned it to allow for the moving of the “Like” button. One thing to keep notice of is the usage of ‘!important’, this is a css trick that will override the already used css code inside of the widget, anything that we change that currently has any values associated with it must use this code or else the original code will still take priority.
![]()
Step 2 – Styling the Widget Header
The second step in customizing the css is to adjust the fan box header. Check the second set of css modifications below.
.fan_box .connect_top{ background: none !important; padding: 0 !important; } .fan_box .profileimage, .fan_box .name_block{ display: none; } .fan_box .connect_action{ padding: 0 !important; }We are basically going to be getting rid of everything in the widget header except for the “Like” button, which we will position to the bottom of our widget later. In lines 1 through 4 we have gotten rid of the light blue background color for the header and removed all of the headers padding. In lines 5 through 7 we have completely removed both the main profile name and image. In lines 8 through 10 we have removed padding associated with the “Like” button that was not needed.
![]()
Step 3 – Styling Fan Connections
The third step in customizing the css is to adjust the actual fb fan connections. Check the third set of css modifications below.
.fan_box .connections{ padding: 0 !important; border: 0 !important; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #666; } span.total{ color: #FF6600; font-weight: bold; } .fan_box .connections .connections_grid { padding-top: 10px !important; } .fan_box .connections_grid .grid_item{ padding: 0 10px 10px 0 !important; } .fan_box .connections_grid .grid_item .name{ font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-weight: normal; color: #666 !important; padding-top: 1px !important; }In lines 1 through 8 of the code we adjusted the padding surrounding the fan box connections, removed the border at the top, and adjusted the font for the line of text that displays “X people like Profile Name”. In lines 9 through 12 of the code we have adjusted the color and font weight of the number of fans displayed. In lines 13 through 15 of the code we have adjusted the padding between the line of text and the actual fan connections. In lines 16 through 18 of the code we have adjusted the padding between the actual fan connections. In lines 19 through 24 of the code we have adjusted the actual fan name, make sure that you DO NOT change the font family, if changed it may cause alignment issues with the connections.
![]()
Step 4 – Positioning the “Like” Button
The fourth and final step in customizing the css is to position the “Like” button. Check the fourth and final set of css modifications below.
.fan_box .connect_widget{ position: absolute; bottom: 0; right: 10px; margin: 0 !important; } .fan_box .connect_widget .connect_widget_interactive_area { margin: 0 !important; } .fan_box .connect_widget td.connect_widget_vertical_center { padding: 0 !important; }With the addition of this block of code the “Like” button will now appear at the bottom right of our fan box widget. How does this work? It works because earlier we used relative positioning on the main widget div in Step 3, whenever relative positioning is used on an element you can then use absolute positioning to position another element anywhere inside of the main element. The way to position the element is by using the attributes top, bottom, left, and right depending on where you want to move the element. In our situation we wanted it to be at the bottom right of our widget so we used the attribute bottom with a position of 0 and right with a position of 10px. The reason we used 10px for right instead of 0 is because we had added 10 pixels of right padding to each of our fan connections, this way the button and fan image will line up correctly. Lines 1 through 6 of the code are used to position the actual div to the bottom right of the widget. In lines 7 through 12 of the code we have removed padding and margin associated with the “Like” button and its surrounding table data so that it will align properly.
![]()
Complete CSS Code
Below is all of the css code from the previous 4 steps combined together.
.fan_box a:hover{ text-decoration: none; } .fan_box .full_widget{ height: 200px; border: 0 !important; background: none !important; position: relative; } .fan_box .connect_top{ background: none !important; padding: 0 !important; } .fan_box .profileimage, .fan_box .name_block{ display: none; } .fan_box .connect_action{ padding: 0 !important; } .fan_box .connections{ padding: 0 !important; border: 0 !important; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #666; } span.total{ color: #FF6600; font-weight: bold; } .fan_box .connections .connections_grid { padding-top: 10px !important; } .fan_box .connections_grid .grid_item{ padding: 0 10px 10px 0 !important; } .fan_box .connections_grid .grid_item .name{ font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-weight: normal; color: #666 !important; padding-top: 1px !important; } .fan_box .connect_widget{ position: absolute; bottom: 0; right: 10px; margin: 0 !important; } .fan_box .connect_widget .connect_widget_interactive_area { margin: 0 !important; } .fan_box .connect_widget td.connect_widget_vertical_center { padding: 0 !important; }
Troubleshooting
If you are trying to edit the css and no changes are showing up, make sure you are adjusting the cache level at the end of the css link in the widget code.
If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still can not get it to work please leave us a comment below and we will respond as soon as possible.
Note
4/20/10 – Facebook has currently just changed the “Become a Fan” button to the new “Like” button. We are awaiting any further changes to the Fan Box and once things appear to calm down we will update this tutorial. Keep checking back…
4/29/10 – This tutorial has been updated to allow full customization of the Facebook Fan Box and positioning of the new “Like” button.










Oh, and I did try grabbing the new fan box code too–made things much worse. I might try starting from scratch with my css and the new code though.
I’ve spent the better part of my day dealing with the style not working since Facebook’s recent changes. I’m on to something here but I’m not sure why.
Here’s where I start getting close to figuring this out:
I made a completely new css file just in case there was some cache issue but still nothing. So I linked to a css file of one of the posters here (Anthony I believe) in case there has been some class change that I have not come across yet. It works! Great, so I copy his style sheet and replace mine with his planning to then make the necessary adjustments. When it’s on my server it no longer works. Even after changing the file’s name one more time. Now…I place my old style sheet (new name) on one of my other servers and viola! It works. So I guess it will be a temporary fix until I figure this out. I don’t have access to the clients Facebook account to try creating a new Fan Box from scratch as DaddyDesign suggested.
Anyone know what’s going on?
Pingback: Comment Customiser votre fanbox facebook ? | KubX
Very helpful, thanks! FYI. Since the addition of the ‘like’ button you need to change the bottom css entry ‘connect_button’ to ‘connect_widget_like_button’.
Hi – Hope this is not too much info, but really could do with some help!
I was so pleased to stumble across your site..just started a blog and cannot in any way shape or form get the ‘like’ or ‘fan’ box to load or come up correctly. I’ve tried .js and eventually html – tweaking a basic code, which does load a box, but it’s a section of my home page! grr..
I’ve gone with a badge in the interim, don’t like that at all. I am absolutely clueless other than with the basics.. maybe you could review my code..
This is what comes up for a fan box widget.. interesting that the box preview doesn’t even load on FB..
my blog is http://beachistheword.blogspot.com
I don’t need anything too fancy, although perhaps an extra row across, if you look at my blog you’ll see why I think that..
window.fbAsyncInit = function() { FB.init({ appId: “120223603844″, xfbml: true }); }; (function() { var e = document.createElement(‘script’); e.async = true; e.src = document.location.protocol + ‘//connect.facebook.net/en_US/all.js’; document.getElementById(‘fb-root’).appendChild(e); }()); Beach and Cruise Vacations on Facebook
Thanks Cullun, we are aware of the change and are making the appropriate changes to the tutorial. In the past few weeks Facebook had been changing the code back and forth a lot and we were waiting for the changes to become official before we updated the tutorial.
Gailene, most likely the problems you were having were when facebook was in the process of changing up the “Become a Fan” button to the like button, during that time there was a lot of wacky things going on with the facebook fan box. Everything seems to be back to normal so try again and hopefully you have better luck this time.
Just a heads up to everyone, this tutorial has been updated as of April 29th, 2010. If you were previously having any types of problems they should all be ok now. Please let us know if any of you are still having issues.
I can’t get Facebook to see my stylesheet at all, and I just uploaded a new one for the first time. I checked in the browser to make sure that it was linking to the correct place, but alas, the widget isn’t applying any styles.
Any ideas what might be causing it? Thanks in advance!
Elle, make sure that you have the ?1 at the end of the link to your style sheet in the widget, if it’s there but still not working try changing the number to 2 or 3.
Let us know if that works for ya.
This is pretty cool. Thanks for the code! I was wondering if there was any way to minify the amount of http requests made by this widget. Also if there is a way to force it to load last on a webpage. Any ideas? Thanks again!
Great website Daddy Design.
I am having a hard time with getting these changes to stick.
http://unitedsocialsports.com/leagues/dc/odb/
I implemented the custom CSS and the code at the tail end of the script and I was able to get the hover to turn off (the font is now reading some other css links style which is why its green) but nopw of the other changes have worked. I copied your full CSS sheet into my custom code area and notta
. I tried using 1-7 on the number for the cache and that didnt seem to work either.
Any ideas? Also, there is that stupid spacing under the box I cant find the cause of either… any help you can give is greatly appreciated!
Thanks for this tutor!
One note though: the current markup code doesn’t manage to always position the LIKE button on the same spot…
This is due to the extra text “You like this” that is only shown once a user is fan (and logged in Facebook), .connect_widget_connected_text
Pingback: iNicolas | Comment customiser la Fan-box de Facebook sur votre blog ?
Pyramus, thanks for pointing that out, it seems that Facebook has once again messed with the button code and changed it around, previously there was no I Like text it was just a different form of the ‘Like’ button. We will update the tutorial again soon.
DDesign,
Any help with my above post? I’m hitting refresh on your site constantly, haha.
Thanks for these great instructions, looks way better than the default box!
However, is it possible to add a link to my facebook profile somewhere? I don’t want to make a header for this like box, because there is no space for it.
Anyone know if this works with iframes? I can’t get it to work.
Hi
Great tutorial and it works perfectly. BUT instead of clicking directly to the person on each profile I’d like it each profile to link to the FAN page itself. How can I do this?
hi! i was wondering is it possible to change the default background colour (transparent) to white? what am i supposed to include in the html code?
Mark, there is no way to change the internal coding for linking on the fan box, we are only able to edit and move things by using CSS.
Kim, you would just add the background color number for white which is #ffffff to the background attribute in Step 1 of the CSS styling instructions.
Use the following in place of Step 1:
.fan_box a:hover{ text-decoration: none; } .fan_box .full_widget{ height: 200px; border: 0 !important; background: #ffffff !important; position: relative; }I think we can probably do it by adding a transparent clickable area over the box. I’m not sure how to do this – if you have any ideas I appreciate your comments.
Very useful tutorial although I have one small question. Once I say I ‘Like’ something I then get text saying “You like this.Unlike” how do i style those elements?
I have to say it’s diving me slightly bonkers so any help would be great!
I’m trying currently to make the fan box catch the css stylesheet, but that won’t work.
I guess there’s something I’m missing.
Here’s the code fan box code :
And the fan box do appear, but that won’t load the css. I tried with other number for the cache breaker, doesn’t work.
I must be blind,
what am i doing wrong?
thx
desp trying to get this to work..
All I get , having registered a Facebook app is “PAGE_NAME on Facebook” displayed
If I run the like box wizards, that displays fine..I have added my api number and the page id
thanks for the reply. but my codes aren’t html. it’s iframe & i’m not really familiar with coding. do i need to convert the codes? how should i do it then?
You answer everyone’s question that posted after me but not mine?
Hey Robert, I took a look at your code but the stylesheet you are linking to does not contain any of the CSS from this tutorial. Try making a completely new stylesheet and name it facebook.css, then copy the CSS code from this tutorial paste it in there, set the number after the link to ?2.
As for the extra spacing under the box try floating the image above it and then put the Facebook Fan Box code into it’s own div and float that, sometimes when items aren’t floated they can create extra unwanted spacing or alignment issues.
Niall, Facebook has constantly been messing with this area of the Fan Box, everytime we have made an update to the tutorial they have changed something else so we are waiting it out to see if the current changes stick for a while, keep checking back for the update.