Posts Tagged ‘css3’

CSS3 Declarations for Web Designers

Wednesday, March 17th, 2010

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.

Creating Rounded Corners Using CSS

Thursday, March 4th, 2010

Rounded corners are a great way to add character to a web site. Rounded corners are also modern and fancy. In this tutorial you will learn how to create rounded corners using simple CSS.

First of all, lets discuss the new CSS3 property which allows you to specify curved corners using CSS. This new CSS property has not yet been finalised, but you will be pleased to know that it works in 3 of the most modern browsers (Firefox, Safari and Chrome). As ever though, Internet Explorer has problems rendering the CSS property which makes curved corners, so an additional Javascript file to force render. Download the file from below.

This technique for rounding corners is about the most robust way I have found of doing it. It uses very little markup and no addition images. It also supports the use of background images on DIVs, even if they do not have rounded corners themselves.

Curvycorners Javascript File (some users may need to right click and ’save link as’)

From here it is very simple to implement:

1. Create your website as you normally would. In the head of each page enter this line of code <script type=”text/JavaScript” src=”curvycorners.js”></script> . This tells the browser to refer to the external Javascript file which you have downloaded from this tutorial. Place the JS file in the root folder for this to work.

2. Apply these CSS attributes to any element you want to apply rounded corners to
-moz-border-radius: 10px;
-webkit-border-radius: 10px;

The code contains a pixel value which, if changed will change the curve on your element. The higher the pixel value the bigger the curve. In addition to this, you can specify diffferent values to each corner by applying the code like this
-moz-border-radius: 10px 20px 10px 20px;
-webkit-border-radius: 10px 20px 10px 20px;

Each figure applies to a different corner, starting with the top left and working around in a clockwise direction.

Example of how code should be applied
.midbox {
height: 280px;
width: 295px;
padding: 5px;
float: left;
margin-left: 5px;
border: 1px solid #CCC;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
background-image: url(images/midboxbg.png);
background-repeat: repeat-x;
text-align: justify;
}

You can apply curvycorners to both classes and IDs.

This technique will make curved corners render in any modern browser simply by using a 3kb javascript file and 2 lines of CSS3.