Embed Facebook Like Button – Right Align with css and Settings

by andrej 9. January 2011 18:28

If you want to embed a Facebook Like button and you want it to align to the right here is a fix with css only:

First, get the embed code from facebook: http://developers.facebook.com/docs/reference/plugins/like

If you embed the XFBML code and the button is smaller than the size you specified, the button will always align to the left. There is nothing you really can do about it due to the iframe structure of the embed code.

facebook like button embed left align

However, if you specify the width of the like button to be 0, the iframe will always be almost the size of the button, which means you can align it whichever way you want.

facebook like button right align set with to zero

There in the settings make sure to select width to equal 0. This leads to the facebook like button element always being the size it actually is. Which allows you to position whichever way you want, to the right for example.

However there is one little trick, you still have to pull: There is a 15 pixel margin to the right of the element. You can align the button exactly to the right by giving your parent html element following css style: position:relative; right:-15px;

The result looks like this:

facebook like button right align

Comments are closed

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.