Stay Updated...

Why invest large sums of money on a website when you are going to use photos taken with a $200 camera? 2 days ago@3PointRoss

StylizedWeb is a web design, Wordpress and tutorials blog, maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Basecamp The Web Design Sketchbook
Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web

Create a CSS3 Button That Degrades Nicely

add to Save to Delicious Save to Stumble Save to Digg

There was a time where creating a nice looking, scalable button required heavy use of images, the sliding doors technique and even some javascript. As it stands a lot of the modern browsers support the css we would like to use to create a nice looking button. Firefox, Safari and Opera all have support for rounder corners, box shadows and text shadows. What used to take six steps and lots of extra mark-up, images and css, now only takes three steps and some simple CSS3.

One of the great perks regarding this technique is that in the event that a user doesn't have a browser that supports the CSS that we will be using, they will still see a nice beveled button - it simply won't look quite as nice.

What We are Going To Do

To create a nice button we have a few major components:

  • A nice background gradient
  • Rounder corners
  • Some nice borders to give it a 3D effect
  • A drop shadow
  • A text shadow (for a nice touch)

In the end we will have a button that looks just like this, only with out using any images behind a few pixel background gradient (and when CSS gradients are supported we can even remove that!).

screenshot

The HTML


<p><a href="#">Example Button</a></p>
<p><a href="#">Example Button</a></p>
<p><a href="#">Example Button</a></p>

As you can see the HTML is very basic, we essentially just need an anchor tag and text. The paragraph is there just to be semantic.

The CSS


.css3button a {
     background: url(background.gif) bottom repeat-x #9eabb3;
     padding: 5px 10px 5px 10px;
     text-align: center;
     font-weight: bold;
     color: #fff;
     text-decoration: none; border: 1px inset #aaa;
     -webkit-border-radius: 8px; width: auto; -moz-border-radius: 8px;  -khtml-border-radius: 8px;  border-radius: 8px;
     -moz-box-shadow: 1px 1px 1px #666;  -webkit-box-shadow: 1px 1px 1px #666;  box-shadow: 1px 1px 1px #666;
     text-shadow: rgba(0,0,0, .5) 0px -1px 0px;
      border-top: inset 1px #ccc; border-left: inset 1px #ccc; border-bottom: solid 1px solid #000; border-right: 1px solid #666;
}

.css3button a:hover  {
     background: #999;
     text-shadow: rgba(0,0,0, .5) 0px 1px 0px;
}

The CSS is a bit more complicated, but still fairly simple. We are really just adding a repeating background image, adding some rounded corners, as well as box and text shadows. The borders add a bit more depth / shading and ensures that if the CSS properties are not supported that the element still retains a beveled appearance.

background

The background image is simple gradient to give the button some depth, in this case I used the following image:

That Simple

That is how easy it is. If you want to play around with the borders you can end up with some pretty nice effects as well.

Examples

Example Button

Example Button

Example Button

Example Button




Leave a comment on Stylized Web Have some feedback? Leave a comment



Talk of the town
  • YaWeZ: Thanks Nice Post
  • Shahnawaz: Thank you for sharing css hack.I like your website articles.
  • sikiş: thx for admin..
  • çeviri büroları: An interesting approach to the topic, but I disagree
  • dizi tv izle: To watch the CineMax Movies TV channel you need the SopCast Player. Free Download here. Online TV, Live...
Amigos

What do you think?





35 Responses so far

By ssk sorgulama
on February 6, 2010

great outcome in such a simple way! I loved to see the proper way to support old browsers…

By Greg WIlker
on December 10, 2009

I personally like it the only issue i see is that background image being to small, however I am on Chrome Mac Beta currently and they have some styling issues to work out that I know of .

By ist
on November 20, 2009

This is awesome! nice job I love it!

By domuz gribi
on November 17, 2009

Thank you good article

By Mike
on October 13, 2009

Thanks for the tutorial definitely something that I am keen to put to use soon.

By Michel
on October 9, 2009

great outcome in such a simple way! I loved to see the proper way to support old browsers.

Thx :)

By xaby
on October 9, 2009

nice trick there. haha pretty cool!

By 3pointross
on October 8, 2009

Great tip Alexander, I will give that a shot!

By Alexander Kulikov
on October 8, 2009

You can even add shadow for ie
a {
zoom:1;filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=1, OffY=1, Color=’#666666′);
}

:)

  1. Jun 24, 2010: 45 Resources & Tutorials for designers and developers | Webdevtuts
  2. Jun 2, 2010: Harika CSS3 Menü Dersleri | Sorbize
  3. Apr 11, 2010: Harika Css3 menu dersleri | web Design Source
  4. Mar 26, 2010: 20 CSS3 Tutorials for Creating Buttons | KSSP
  5. Mar 17, 2010: Create a CSS3 Button That Degrades Nicely | LearnersTutorials
  6. Mar 15, 2010: Bookmarks for March 15th from 01:20 to 01:23 | Travis' Blog
  7. Feb 26, 2010: Designing CSS Buttons: Techniques and Resources | WebsGeek
  8. Feb 23, 2010: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop
  9. Feb 23, 2010: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop
  10. Feb 23, 2010: 20 CSS3 Tutorials and Techiques for Creating Buttons | The New Drop
  11. Feb 20, 2010: 10 Amazing CSS3 Tutorials and Techiques for Creating Buttons | denbagus blog
  12. Feb 18, 2010: 20 + CSS3 Tutorials and Techiques for Creating Buttons | Seventy Seven magazine
  13. Feb 18, 2010: 20 CSS3 Tutorials and Techiques for Creating Buttons « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates
  14. Feb 15, 2010: 20 CSS3 Tutorials and Techiques for Creating Buttons - Speckyboy Design Magazine
  15. Dec 8, 2009: All about Buttons, Buttons … & Buttons (CSS, Glowing, Javascript, Advance) | Ajax CSS and WEB2.0 Resource Directory. Ajax Effects, Components Drag Drop, CSS Gallery, AJAX CSS PHP Tutorial AjaxCSS.com
  16. Nov 19, 2009: Designing CSS Buttons | Rolandyh Blogging
  17. Nov 18, 2009: Designing CSS Buttons: Techniques and Resources | Buddy's Blog
  18. Nov 18, 2009: Designing CSS Buttons: Techniques and Resources | Buddy's Blog
  19. Nov 18, 2009: typoglyphic.com » Designing CSS Buttons: Techniques and Resources – Smashingmagazine.com
  20. Nov 18, 2009: Designing CSS Buttons: Techniques and Resources - Smashing Magazine
  21. Nov 7, 2009: Больше, больше эффектов c CSS3! | rotorweb.ru | Проблемы и решения в Web-дизайне
  22. Oct 19, 2009: Podcast #75: Jeremy Keith Interview, Google Wave « The BAT Channel
  23. Oct 19, 2009: Podcast #75: Jeremy Keith Interview, Google Wave « AccessTech News
  24. Oct 13, 2009: GuyTouch » 88 lien pour Worpress, jquery, javascript, tout pour le web
  25. Oct 10, 2009: 88 liens sur Wordpress, jQuery, typographie, CSS, webdesign …
  26. Oct 10, 2009: Create a CSS3 Button That Degrades Nicely | Design Newz