Introduction

In this article, we are going to create a button and give it feeling like 3D using HTML5 and CSS3.

Starting from HTML Document

  1. <body>
  2. <a href="#" class="red">Click Here</a>
  3. </body>
Preview
image1.JPG

Styling it using CSS

  1. .box {
  2. background-color: #e1e1e6;
  3. width: 400px;
  4. height: 100px;
  5. border: 1px solid black;
  6. border-radius: 5px;
  7. }
  8. /*for styling box inside which button is placed*/
  9. .red {
  10. position: relative;
  11. top: 36px;
  12. left: 35%;
  13. text-decoration: none;
  14. color: #fff;
  15. background: #cb2727;
  16. text-align: center;
  17. padding: 20px 30px;
  18. width: 115px;
  19. border-radius: 5px;
  20. border: solid 1px #ec3838;
  21. transition: all 0.1s;
  22. -webkit-box-shadow: 0px 9px 0px #a81515;
  23. /*for opera and safari*/
  24. -moz-box-shadow: 0px 9px 0px #a81515;
  25. /*for mozilla*/
  26. -o-box-shadow: 0px 9px 0px #a81515;
  27. /*for opera*/
  28. -ms-box-shadow: 0px 9px 0px #a81515;
  29. /*for I.E.*/
  30. }
Here we set text-decoration to none so that link underline removed. After that adjusted color and background-color. Then set text-align and padding. Important Step here is transition and box-shadow.
CSS3 transitions are effects that let an element gradually change from one style to another.
Preview
image2.JPG

Final step (Adding CSS for :active)

The : active selector is used to select and style the active link. A link becomes active when you click on it.
  1. .red:active {
  2. -webkit-box-shadow: 0px 2px 0px #a81515;
  3. position: relative;
  4. top: 43px;
  5. }
The main trick behind this button's working is that decrease box-shadow and move the position slightly down so that appears pressing down
Preview (working)
image3.JPG
That's all.