30. April 2008 by Janko in Tutorials | tags:

This article will show you how to create fancy buttons using CSS sliding doors technique. It is much better to use this technique than to use image buttons because you can apply the style to any link and at the same time you don't have to create an image for each button. I posted this one on Morning Break weblog but due to its popularity I decided to publish it here.

What is sliding doors technique?

The technique is very simple. If we want to have a dynamic-width button, we have to find a way to stretch it horizontally. We will accomplish this if we create two background images that will define the button: one for the left side and one for the right side - like in the example below.

  LEFT                                                                                                           RIGHT

  

Smaller, right image will slide on the top of the larger, left image (that why it is called sliding doors). The more right image slides to the left, the narrower button will be and vice versa. The image below shows the technique.

Styling the button

First, let's take a look at the HTML elements that will simulate button. We have <span> element within the <a> element. Span element contains left, wider image and text. The width of the text will determine the size of the button.

<a class="button" href="#"><span>Submit</span></a> 

Now let's take a look at the CSS code. We have a .button class that will be applied to <a> element and .button span class that will be applied to <span> element within <a> element. We also have .button:hover span that will change the font style within <span> element.  And that's all. Simple, eh? The comments in the code below describes each element.

a.button {
    /* Sliding right image */
    background: transparent url('button_right.png') no-repeat scroll top right; 
display: block;
float: left;
height: 32px; /* CHANGE THIS VALUE ACCORDING TO IMAGE HEIGHT */
margin-right: 6px;
padding-right: 20px; /* CHENGE THIS VALUE ACCORDING TO RIGHT IMAGE WIDTH */
/* FONT PROPERTIES */
text-decoration: none;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:bold;
}
a.button span {
/* Background left image */ 
background: transparent url('button_left.png') no-repeat; 
display: block;
line-height: 22px; /* CHANGE THIS VALUE ACCORDING TO BUTTONG HEIGHT */
padding: 7px 0 5px 18px;
} 
a.button:hover span{
text-decoration:underline;
}

The result will look like the examples below.

UPDATE 14.05.2008: You can see it "in action" on example page.

I've made a few more designs that you can use with the CSS code above. Each design consist of two images, like in our example. Enjoy!

  1.  
  2.   button_right_02
  3.  
  4.  
  5.  
  6.  

If you liked this article why don't you share it:

Make fancy buttons using CSS sliding doors technique (via @jankowarpspeed) Share this on StumbleUpon Share this on delicious Share this on Digg Share this on Dzone Share this on DesignBump Send this to friend

Comments

Pingbacks and trackbacks

  1. Trackback from DotNetKicks.com CSS sliding doors technique
  2. Pingback from austinwilliams.org AustinWilliams.org » links for 2008-05-13
  3. Pingback from james.a.arconati.net links for 2008-05-13 at James A. Arconati
  4. Pingback from programatik.wordpress.com Dica de CSS: Botão deslizante « namespace Programatik
  5. Pingback from jeremiahtolbert.com links for 2008-05-13 | JeremiahTolbert.com
  6. Pingback from velcro-city.co.uk Links for 14-05-2008 | Velcro City Tourist Board
  7. Pingback from straighten.jp links for 2008-05-14 | straighten
  8. Pingback from abhijeetmaharana.com Gwt-Ext and Number Madness | Abhijeet Maharana
  9. Trackback from pligg.com Fancy CSS Buttons Tutorial
  10. Pingback from epdsn.com epdsn’s blog post » Blog Archive » Make fancy buttons using CSS sliding doors technique
  11. Pingback from mitkinsprojects.com Mitkins Projects Blog :: Great blog post explaining how to make CSS sliding doors : Mitkins Projects!, The Art of Web Design
  12. Pingback from jay-han.com Jayhan Loves Design & Japan » Button design PSD resource download
  13. Pingback from lyxia.org 10 tutos pour créer de sublimes boutons en CSS
  14. Pingback from catswhocode.com Top 10 CSS buttons tutorial list
  15. Pingback from rubendomfer.com 10 tutoriales para crear botones CSS en rubendomfer
  16. Pingback from deliblog.net 10 adet Css Butonu | DeliBlog | Deli birinin çıkardıkları
  17. Pingback from cosassencillas.com Selección de 10 tutoriales para crear botones con CSS » Cosas sencillas
  18. Pingback from comentaomuere.com Una de botones: los 10 mejores tutoriales de botones en CSS » Comenta o Muere | Actualidad, Humor, Tecnología, Política, Ciencia, Música… y otros muchos temas de los que merece la pena hablar.
  19. Pingback from instantshift.com 30 Excellent CSS Based Navigation and Buttons Tutorial | instantShift
  20. Pingback from sharebrain.info Dynamic buttons using CSS sliding doors technique | Sharebrain »
  21. Pingback from cogzideltemplates.com Usefull links for CSS Programmers | Cogzidel Templates Blog
  22. Pingback from tripwiremagazine.com 150 Worth Knowing Web Developer Tools and Techniques | tripwire magazine
  23. Pingback from blueprint.intereactive.net Building Better Buttons - The Blueprint - Intereactive Blog
  24. Trackback from pligg.com Make fancy buttons using CSS sliding doors technique
  25. Pingback from parandroid.com 11大CSS按钮教程 | 帕兰映像
  26. Pingback from answerspluto.com list of urls - 5 « Answers Pluto
  27. Pingback from jaceju.net 網站製作學習誌 » [Web] 連結分享
  28. Pingback from anton.shevchuk.name CSS для начинающих. CSS кнопки это просто
  29. Pingback from huibit05.com 26 Essential Submit Button Enhancements | huibit05.com
  30. Pingback from maquetacionweb.com Top 10 Botones CSS con tutorial | Maquetación web
  31. Pingback from techflaps.com Techflaps | 15 Tutorials on Creating CSS Navigaton Menus with Sliding Doors Effect
  32. Pingback from blog.herupermana.net 22 CSS Button Styling Tutorials and Techniques | Heru Permana Blog
  33. Pingback from blogfreakz.com buttons | blogfreakz.com
  34. Pingback from goeshare.com Top 10 excellent CSS Button design Tutorials | Goeshare
  35. Pingback from nucao.com 几种比较漂亮的CSS按钮效果 | 网站应用 | 朽木自雕
  36. Pingback from webcssdesign.com 22 tutoriels pour boutons CSS | WebCssDesign
  37. Pingback from devezine.com Make fancy buttons using CSS sliding doors technique
  38. Pingback from csslovers.co.cc CSS Lovers, Web 2.0 Directory and Resources » Blog Archive » 10 Awesome CSS buttons tutorial list
  39. Pingback from speckyboy.com 22 CSS Button Styling Tutorials and Techniques : Speckyboy Design Magazine
  40. Pingback from diythemes.com add more links - css classes? - DIYthemes Forums
  41. Pingback from kathirpositive.wordpress.com Top 10 CSS buttons tutorial list « Kathirvel K
  42. Pingback from kathirpositive.wordpress.com Make fancy buttons using CSS sliding doors technique « Kathirvel K

Add comment

   
        Country flag
biuquote
Loading