By popular demand, here are instructions to add icons to your site that will stick to the sidebar, even when scrolling up or down the page. Inspired by various resources that I found on the web, I’ve tried to put together a set of instructions that will make this as easy as possible.
The result will look like this (except in IE6, which will mess up).
These are the ingredients that we need to achieve this:
- Icons that you would like to display
- HTML code that will display the icons, and will link to the required locations
- CSS code that will make sure the icons stick to side of the site
Icons that you would like to display
First of all, you need to pick a set of icons that you wish to display, these can be social icons, or, as seen on the iThemes website, icons linking to other sites, or any icons you wish to use. Make sure all icons have the same dimensions, and make sure that the icons you download are free to use, or if you have to make an attribution to the designer (which is always a good thing).
For the sake of this tutorial, the icons (in this case 48px by 48px) are stored in a subfolder images/icons/ in your theme folder.
HTML code that will display the icons, and will link to the required locations
The html code to display the icons, and make sure they link to the proper location is straightforward. Preferably, the code is added right after the opening <body> tag, that can usually be found in header.php.
In this example, 4 icons will be displayed linking to my twitter, facebook and linkedin profile, and a link to the RSS feed of my site.
<div id="fixed_icons">
<a href="http://twitter.com/vanweerd" id="twitter" title="Follow us on Twitter"></a>
<a href="http://www.facebook.com/ronaldvanweerd" id="facebook" title="Facebook Profile"></a>
<a href="http://nl.linkedin.com/in/vanweerd" id="linkedin" title="LinkedIn Profile"></a>
<a href="http://feeds.feedburner.com/VanWeerd" id="rss" title="RSS feed"></a>
</div>
Note that the code is wrapped in a div container, that we will use in the CSS, and note the id’s added to each link. This id will be used by the CSS code to display the appropriate icon.
CSS code that will make sure the icons stick to side of the site
Finally, you need to add the following code to the stylesheet. The first two selectors make sure that the icons are fixed to the side of your side. The lower part will make sure that the proper icons are displayed for each id used in the hyperlink in the HTML code.
#fixed_icons {
background: transparent;
width: 48px;
position: fixed;
top: 15%;
right: 0.20%;
}
#fixed_icons a {
display: block;
text-indent: 24px;
height: 48px;
padding-bottom:3px;
text-decoration: none;
}
#fixed_icons #twitter { background: url("images/icons/twitter.png") no-repeat; }
#fixed_icons #facebook { background: url("images/icons/facebook.png") no-repeat; }
#fixed_icons #linkedin { background: url("images/icons/linkedin.png") no-repeat; }
#fixed_icons #rss { background: url("images/icons/feed.png") no-repeat; }
Using this code as a starting point, you can finetune and tweak the icon positions using the highlighted lines:
top: 15%; right: 0.20%;the
top property specifies how far from the top of the page the icons will be displayed, the right property will stick the icons to the right site, leaving a 0.20% gap. Changing right to left will obviously move the icons over to the left side of the site.
I hope you enjoyed this, and that the instructions are clear, leave a comment if you wish to show off your implementation!
In a followup article, I will explain how you can apply all these changes without modifying any theme files other than the functions.php file.



Hey, that’s a great tip. I’m a motivational speaker and sales trainer …. certainly not a coder or developer and that worked like a charm! Just would love to know how to create hover effects with this sidebar trick.
Thanks!
Hi,
to add a hover effect, create hover images, based on the existing (add a bit of shading, or highlighting) and simply add the following lines to the css,
#fixed_icons #twitter:hover { background: url(“images/icons/twitter_hover.png”) no-repeat; }
#fixed_icons #facebook:hover { background: url(“images/icons/facebook_hover.png”) no-repeat; }
#fixed_icons #linkedin:hover { background: url(“images/icons/linkedin_hover.png”) no-repeat; }
#fixed_icons #rss:hover { background: url(“images/icons/feed_hover.png”) no-repeat; }
that should do the trick,
Ronald
Hey Ronald, I am not sure if I am doing something wrong but I’m 99% sure I’m doing it right and when i hover over the images they just disappear ? Is there some code I need to add in the header file ?
Thank You,
Cody
Did you ever figure out why the icons disappeared? I have the same problem.
Make sure you uploaded the hover images to the /images/icons dir
Sorry, I spoke before I should have, I’m having the same troubles.
What is the URL to your site? I could have a quick peek for you.
Hey Ronald, I just wanted to thank you for this excellent tutorial. I’d looked in the past for a step by step guide for implementing the icons, but hadn’t found anything until I came across this. You made it seem so easy. In fact, I even got the code working on my phpbb forums as well. Thanks!
Craig
Hey Ron,
This is great and I am attempting to use this in another way – hope you can help.
on the site http://64.79.132.174/~capstone/ you’ll see two sets of social icons, one below the logo and the one I am attempting to add as an “absolute” vs “fixed”. The reason I am doing this is because the when you view the site in IE it squishes up the icons with the way i originally did this.
So here is what I am trying to do – I would like to line the icons up side-by-side instead of on top of each other. Then use either padding or margin to place the icons over the set that is currently under the logo. Once I get everything lined up – i’ll delete the old ones.
I have tried the following css display types:
inline-block;
inline-table;
table-row-group;
table-row;
and I can not get the icons to go horizontal?
Any help would be appreciated!
Hi Rick,
here’s my (!) simple solution to fix the IE6 issue:
<!––[if lte IE 6]>
<style type=”text/css”>
#fixed_icons { display:none; }
</style>
<![endif]––>
so the 2% of die hard IE6 users that visit my site won’t see the icons. Tough.
Anyway, there’s no easy fix to your CSS, but note that 10em is huge! More here: http://jontangerine.com/log/2007/09/the-incredible-em-and-elastic-layouts-with-css.
Adding display: inline; on the fixed_icon div selector lines them up horizontally, but there are huge gaps. Maybe it helps you though.
Ron,
I do not think I explained my situation clearly (my bad).
I wasnt looking for a fix to the IE6 issue – I was looking to replace the current horizontal set of social Icons with a modified solution that you blogged about above.
It looked simple enough for me to do, but the problem is – when you visit http://64.79.132.174/~capstone/ you see your modified version is listed vertically in the top left – the ones i am going to delete run horizontally before the Capstone logo.
What I would like to do, is make the vertical ones horizontal, then move them below the capstone logo… once i have this completed – I will delete the old horizontal ones
I know I should have probably placed this in the support forum – but when I saw your above solution, I thought it may be easier to communicate here.
Sorry for any confusion
Hi Ron – I’m in the process of redoing a site using Builder and when I implement the above instructions the icons appear in the upper left corner of the site. For Builder does the html code still go in the header.php file or somewhere else?
Thanks,
Dale
Hi Dale,
it doesn’t really matter where you add the code, as long as the html code is anywhere in between the
and tag, and the css code is in your stylesheet. In Builder you can’t use the header.php, since the opening tag is not in that file. You can add an html module to add the code.Ronald
It wacks out my beta site (Builder) in IE (looks fine in Firefox): http://www.stampallnight.com. Any ideas?
http://stampallnight.com... my question didn’t post, I apologize if this ends up a duplicate. This solution looks fine in Firefox but not in IE 8 (it makes the Builder theme whack out). Also my ‘hovered’ image is uploaded properly, however instead of the ‘hover’ image, there is no image.
I was loving my new little icons to the side and just realized that they are gone… the only two plugins that I’ve added were SexyBookmarks & W3 Total Cache. I did some optimizing and added stuff to the .htaccess but I’m not sure when they disappeared. Admit it, you were jealous and stole them back…
Hi Amy,
must be one of the plugins,
Ronald
I disabled them for an entire day and they didn’t come back. I had added Google analytics in the footer with it, and I also took that out for a few hours, they didn’t come back. I haven’t touched the code at all. It is the same code as in stampallnight.com (where I put them originally to test).
Amy, on your request, I have reversed the order of the comments. Hope this works better for you. It actually makes more sense to me as well
Thank you for the offline help… adding it to the functions.php instead worked. Yeah!
This seems super simple for an html site, but I am trying to implement this using Builder with a child theme.
Questions:
1. Which style sheet do I add the css code to? With Builder and child themes and the Builder style manager, its confusing.
2. What syntax do I use to put the html in the functions.php file? Does it go at the beginning or the end?
Please help.
Thanks,
Mark
Pingback: Buttons on side of web page
Please help… one more request
Mark says:
September 24, 2010 at 03:39
This seems super simple for an html site, but I am trying to implement this using Builder with a child theme.
Questions:
1. Which style sheet do I add the css code to? With Builder and child themes and the Builder style manager, its confusing.
2. What syntax do I use to put the html in the functions.php file? Does it go at the beginning or the end?
Please help.
Thanks,
Mark
Hi Mark,
1. in Builder, add the CSS code to the child theme’s stylesheet style.css. You should not use the Stylemanager since this is not native Builder code.
2. there is no need to modify functions.php, As I stated in an earlier reply, you can add the code to an html module and add that to your layouts.
Or if you want to use a function, check out my other post on how to add a full width header and footer which has an example of how to insert code in Builder using functions.php.
hope that helps,
Ronald
I am still failing to get this to work. My only guess is that there is an overflow:hidden; somewhere making it disappear.
I added this trick to the itheme addington theme & noticed 1 issue. The icons would scroll under the header & footer unless I changed the “top: 15%; ” to some ridiculous high number like 65% & added a bottom percentage of 75%.
Solution: I added a z-index value of 100%. It works great now! Thanks for the neat trick.
Thanks Ronald for the great code and inspiration.
I had some troubles with bad characters when I copy/pasted the code but finally found the problem.
I used 32px and 64px icons so when you hover the icons grow in size!
Check it out at: http://BobRandklev.com
Thanks
Hi Bob,
for a much more sophisticated “growing icons” script, check this one out: http://www.ndesign-studio.com/blog/css-dock-menu
Since I am new to Builder, exactly how do you add an HTML module to a layout?
Pingback: Add Floating Icons to WordPress Using CSS | Ridhuan's Blog
I’d like to use the technique you have on the right of this page. Upon scroll the box opens for content. Are the instructions the same just use the hoover code in the comments area?
Thanks for the great tips.
Hi Lou Anne,
for the slide out boxes on the right, I used this technique, and merged it with the WordPress related posts plugin. I’ve made it into a plugin for myself, but not one that is ready for distribution.
Ronald,
Do you think this can be a plugin offered at pluginbuddy.com in the near future? Where you can add content and your own icons?
It is just such a cool feature and makes your website look great!
Thanks,
Brian
Pingback: 非插件添加社会化书签到WordPress博客
I am working on a site mock-up using Builder. This has helped out so much! However, I put a larger icon at the top (ie. Follow us), and I would like the following icons to be centered underneath (i.e. facebook icon, etc.). How would I do this?
Thank you!
Good morning,
How can I put a laterla sidebar as in the right in this website.
Look forward to hearing from you soon,
Regards