UPDATED 15/03/2010
CSS3 is still under development but things are moving fast. This post/tutorial aims to provide Web Designers with the latest CSS3 declarations and their usage and compatibility. This is the ultimate resources for any Web Designer who relies on CSS to build web sites.
Gradient Border
The gradient border property is a very recent addition to CSS3 and currently works in only Firefox. It has the ability to create a gradient border which, up until recently could only be achieved using some tricky mark up and your favourite graphics program
.border: 8px solid #000;
-moz-border-bottom-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-top-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-left-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-right-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
padding: 5px 5px 5px 15px;
Border Radius
Border radius is becoming a popular technique. Like many new CSS3 declarations, up until recently this technique could only be achieved by cheating using images and or Javascript. This easy to use declaration works in new versions of Firefox and Safari.
* -moz-border-radius-topleft / -webkit-border-top-left-radius
* -moz-border-radius-topright / -webkit-border-top-right-radius
* -moz-border-radius-bottomleft / -webkit-border-bottom-left-radius
* -moz-border-radius-bottomright / -webkit-border-bottom-right-radius
Drop Shadow
This fantastic new feature is actually called Box Shadow as opposed to Drop Shadow and works with Firefox and Safari. The code for this is below. It take 3 lengths and a colour as its attributes:
1. the horizontal offset of the shadow, positive means the shadow will be on the right of the box, a negative offset will put the shadow on the left of the box;
2. the vertical offset, a negative one means the box-shadow will be on top of the box, a positive one means the shadow will be below the box;
3. the blur radius, if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be.
box-shadow: 10px 10px 5px #888;
padding: 5px 5px 5px 15px;
Multiple Backgrounds on an Element
CSS3 will allow multiple background images on one element (currently only supported by Safari). This is done simply by separating the background image source with commas. This CSS3 property promised to negate the need for multiple DIVs to achieve a simple effect. For example:
background: url(top_bg.gif) top left no-repeat,
url(header.jpg) top 11px no-repeat,
url(footer.gif) bottom left no-repeat,
url(mid_bg.gif) left repeat-y;
Opacity
Opacity has always been the bugbear of any Web Designer, and despite the increased popularity of PNG, it still has its flaws. This new CSS3 declaration will prove very popular and reduce the amount of work required for semi-transparency in the future.
<div style=” background: rgb(255, 0, 0) ; opacity: 0.2;”></div>
<div style=” background: rgb(255, 0, 0) ; opacity: 0.4;”></div>
<div style=” background: rgb(255, 0, 0) ; opacity: 0.6;”></div>
<div style=” background: rgb(255, 0, 0) ; opacity: 0.8;”></div>
<div style=” background: rgb(255, 0, 0) ; opacity: 1;”></div>
Each example above gives a different opacity value. The value can be seen at the end of each line. 0.2 is equivalent to 20%,0.4 to 40% and so on.
Text Shadow
Creating text effects with CSS3 is easy thanks to some new declarations which allow text shadows without the use of your graphics program. The declaration is simple and works in new versions of Safari, Firefox and Opera.
text-shadow: 2px 2px 2px #000;
CSS3 Web Fonts
Since the dawn of The Web, designers have been restricted to using a set group of fonts which are guaranteed to work on every computer in every location. This is soon to become history with a new CSS3 declaration using @font-face. This new declaration embeds the font so your user can view the web site in their browser with the correct font, even if they don’t have it installed on their machine.
First, the font needs to be embedded (remember, only licenced True Type .ttf or Open Type .otf fonts can be used):
@font-face {
font-family: Delicious;
src: url(‘Delicious-Roman.otf’);
}
@font-face {
font-family: Delicious;
font-weight: bold;
src: url(‘Delicious-Bold.otf’);
}
Once embedded, the font needs to be called using this CSS3 declaration:
h3 { font-family: Delicious, sans-serif; }
This currently only works in Safari but will hopefully be cross browser compatible by 2011.