CSS3 Box-Shadow with Inset Values – The Aqua Button ReReVisited!
This is my third article on CSS3 No Image Aqua Buttons. The previous articles include:
- CSS3 Gradients: No Image Aqua Button
- CSS3 Aqua Button – Revisited for Firefox 3.6
- And this one – Read on!
Since Smashing Magazine has selected the original Aqua button demo for their article, “50 Brilliant CSS3/JavaScript Coding Techniques”, I have had so much more visitors to my blog.
This resulted quality developers leave useful comments and tips for me – thank you, Zoley for suggesting using box-shadow
with the inset value, and a big thank you to Jim for actually re-writing the Aqua button with the technique!!!
So, now the CSS3 Aqua button is revised with semantic markup (no more “glare” div! Yes, I complained it by myself before!) and shorter CSS.
And this time, no CSS gradients! – use CSS box-shadow
property with multiple inset values to draw layers of inner-shadows to create the visual effect.
Syntax
box-shadow: none | [inset? && [ <offset-x> <offset-y> <blur-radius>? <spread-radius>? <color>? ] ]#
Values
from Mozilla Developer Center:
inset (optional)
If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content).
The presence of the inset
keyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn above background, but below border and content.
**
**
**
**
Note – The box-shadow
property has been removed from W3C CSS3 Background Candidate recommendation document.
The Entire Code!
Use -moz
and -webkit
prefix for box-shodow
to support these browsers. For Opera, there’s no need to add -o
.
Also, notice there are three inset
values are defined for detailed visual effects!
<input type="button" class="new-aqua" value="Login">
input[type=button].new-aqua {
width: 155px;
height: 35px;
background: #cde;
border: 2px solid #ccc;
border-color: #8ba2c1 #5890bf #4f93ca #768fa5;
font: 600 16px/1 Lucida Sans, Verdana, sans-serif;
color: #fff;
text-shadow: rgba(10, 10, 10, 0.5) 1px 2px 2px;
text-align: center;
vertical-align: middle;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
border-radius: 16px; -moz-border-radius: 16px; -webkit-border-radius: 16px;
box-shadow: 0 10px 16px rgba(66, 140, 240, 0.5), inset 0 -8px 12px 0 #6bf, inset 0 -8px 0 8px #48c, inset 0 -35px 15px -10px #7ad;
-moz-box-shadow: 0 10px 16px rgba(66, 140, 240, 0.5), inset 0 -8px 12px 0 #6bf, inset 0 -8px 0 8px #48c, inset 0 -35px 15px -10px #7ad;
-webkit-box-shadow: 0 10px 16px rgba(66, 140, 240, 0.5), inset 0 -8px 12px 0 #6bf, inset 0 -8px 0 8px #48c, inset 0 -35px 15px -10px #7ad;
}
.new-aqua:hover {
text-shadow: rgb(255, 255, 255) 0px 0px 5px;
}
View the live demo page! This new aqua button works on FF 3.6, Webkit 4 (the current Safari 4 doesn’t support inset box-shadow yet), Chrome 4 and Opera 10. (But fails on 10.1 on Mac).
* Edited on Feb.5 – Opera 10.1 fail and Safari4 (I noticed this works only on Webkit Nightly after published this!)
And again, a huge thanks to Jim Green for the revised CSS!
References
- Safari CSS Reference by Apple Safari Dev Center
- -moz-box-shadow by Mozilla Developer Center
- CSS3 borders, backgrounds and box-shadows by Dev.Opera
comments powered by