Build Kick-Ass Practical CSS3 Buttons
Jeffrey Way
•
2 min read
What once required background images and icons can now be created with plain-old CSS. Because modern browsers have access to things like box shadow, gradients, rounded corners, text-shadows, and font-face, we can finally take advantage of this and remove any need for images, when creating visual elements, such as buttons!
Full Screencast
Final Code
1 |
|
2 |
<!DOCTYPE html> |
3 |
|
4 |
<html lang="en"> |
5 |
<head> |
6 |
<meta charset="utf-8"> |
7 |
<title>CSS3 Buttons</title> |
8 |
<style> |
9 |
|
10 |
/* CUSTOM FONT */
|
11 |
@font-face { |
12 |
font-family: 'EfonRegular'; |
13 |
src: url('font/EFON-webfont.eot'); |
14 |
src: local('EfonRegular'), url('font/EFON-webfont.woff') format('woff'), url('font/EFON-webfont.ttf') format('truetype'), url('font/EFON-webfont.svg#webfont') format('svg'); |
15 |
font-weight: normal; |
16 |
font-style: normal; |
17 |
}
|
18 |
|
19 |
body { |
20 |
width: 400px; |
21 |
margin: 200px auto; |
22 |
background: #666; |
23 |
}
|
24 |
|
25 |
.button { |
26 |
width: 400px; |
27 |
height: 100px; |
28 |
line-height: 100px; |
29 |
color: white; |
30 |
text-decoration: none; |
31 |
font-size: 50px; |
32 |
font-family: helvetica, arial; |
33 |
font-weight: bold; |
34 |
display: block; |
35 |
text-align: center; |
36 |
position: relative; |
37 |
|
38 |
/* BACKGROUND GRADIENTS */
|
39 |
background: #014464; |
40 |
background: -moz-linear-gradient(top, #0D658E, #0C577A 50%, #014D71 51%, #003E5C); |
41 |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0E658E), color-stop(.5, #0C577A), color-stop(.5, #014D71), to(#003E5C)); |
42 |
|
43 |
/* BORDER RADIUS */
|
44 |
-moz-border-radius: 10px; |
45 |
-webkit-border-radius: 10px; |
46 |
border-radius: 10px; |
47 |
|
48 |
border: 1px solid #368DBE; |
49 |
border-top: 1px solid #c3d6df; |
50 |
|
51 |
/* TEXT SHADOW */
|
52 |
|
53 |
text-shadow: 1px 1px 1px black; |
54 |
|
55 |
/* BOX SHADOW */
|
56 |
-moz-box-shadow: 0 1px 3px black; |
57 |
-webkit-box-shadow: 0 1px 3px black; |
58 |
box-shadow: 0 1px 3px black; |
59 |
}
|
60 |
|
61 |
/* WHILE HOVERED */
|
62 |
.button:hover { |
63 |
background: #014464; |
64 |
background: -moz-linear-gradient(top, #0c5f85, #0b5273 50%, #024869 51%, #003853); |
65 |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0c5f85), color-stop(.5, #0b5273), color-stop(.51, #024869), to(#003853)); |
66 |
}
|
67 |
|
68 |
/* WHILE BEING CLICKED */
|
69 |
.button:active { |
70 |
-moz-box-shadow: 0 2px 6px black; |
71 |
-webkit-box-shadow: 0 2px 6px black; |
72 |
}
|
73 |
/* FONT GLYPH (MOSTLY FOR FUN) */
|
74 |
.button:before { |
75 |
font-family: EfonRegular; |
76 |
content: 'v'; |
77 |
color: #09232F; |
78 |
font-size: 90px; |
79 |
float: left; |
80 |
margin-left: 35px; |
81 |
margin-right: -10px; |
82 |
text-shadow: 0 1px 0 #4190AF; |
83 |
}
|
84 |
|
85 |
</style> |
86 |
</head> |
87 |
<body> |
88 |
<a href="#" class="button"> Follow Me </a> |
89 |
|
90 |
</body> |
91 |
</html> |
Conclusion



The truth is that it would probably be smarter to use a tiny image for the Twitter-bird icon. But, the goal was to achieve this effect with all CSS! What do you think?



