Reputation: 607
Is it possible to create this kind of button (with 3 states and variable width) completely with CSS3? Or at least avoid having images for every button?
ok with cssbuttongenerator and jsfiddle i'm at this point: http://jsfiddle.net/Wdzje/ but its still not quite yet where i wanna be (color,border)! can someone help me out? Also the actve state isnt ready yet
Upvotes: 1
Views: 5150
Reputation: 425
Yes it is possible, there are numerous resources which help you achieve this. Check out http://www.cssbuttongenerator.com/
Or expand upon this:
Button:
<a href="#" class="myButton">my button</a>
CSS
.myButton {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
}
.myButton:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}
.myButton:active {
position:relative;
top:1px;
}
Upvotes: 4
Reputation: 4660
yes, it's possible.
you can use the css3 properties like radius, gradient, text shadow, box shadow to create something like the button you want..
look at the fiddle: http://jsfiddle.net/vLVLJ/
Here's the markup just in case the link dies:
<div class="button">
button!
</div>
And the CSS:
.button {
border: 1px solid #696;
padding: 60px 0;
text-align: center; width: 200px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: #666 0px 2px 3px;
-moz-box-shadow: #666 0px 2px 3px;
box-shadow: #666 0px 2px 3px;
background: #EEFF99;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#EEFF99), to(#66EE33));
background: -webkit-linear-gradient(#EEFF99, #66EE33);
background: -moz-linear-gradient(#EEFF99, #66EE33);
background: -ms-linear-gradient(#EEFF99, #66EE33);
background: -o-linear-gradient(#EEFF99, #66EE33);
background: linear-gradient(#EEFF99, #66EE33);
}
Upvotes: 2
Reputation: 9758
Here's your button with 3 working states using CSS3.
Take a look at the fiddle
<button>
I am a button!
</button>
button {
cursor: pointer;
border: none;
color: #fff;
padding: 10px 20px;
font-weight: 700;
text-align: center;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
box-shadow: 2px 2px 3px #999;
background: #32CD32;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#32CD32), to(#32AB32));
background: -webkit-linear-gradient(#32CD32, #32AB32);
background: -moz-linear-gradient(#32CD32, #32AB32);
background: -ms-linear-gradient(#32CD32, #32AB32);
background: -o-linear-gradient(#32CD32, #32AB32);
background: linear-gradient(#32CD32, #32AB32);
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
transition: all 500ms ease-in-out;
}
button:hover {
background: #32AB32;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#32AB32), to(#32CD32));
background: -webkit-linear-gradient(#32AB32, #32CD32);
background: -moz-linear-gradient(#32AB32, #32CD32);
background: -ms-linear-gradient(#32AB32, #32CD32);
background: -o-linear-gradient(#32AB32, #32CD32);
background: linear-gradient(#32AB32, #32CD32);
}
button:active {
background: #329932;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#32AB32), to(#329932));
background: -webkit-linear-gradient(#32AB32, #329932);
background: -moz-linear-gradient(#32AB32, #329932);
background: -ms-linear-gradient(#32AB32, #329932);
background: -o-linear-gradient(#32AB32, #329932);
background: linear-gradient(#32AB32, #329932);
}
Upvotes: 1