CSS3
CSS3 Opacity
0The Opacity Property is slightly different then RGBA and HSLA which was discussed in CSS3 Colors.
Opacity v. RGBA & HSLA
Indeed RGBA has the addition of the "alpha" or opacity value like so:
{code type=css}
background-color:rgba(127, 60, 87, 0.4);
background-color:hsla(68, 100%, 50%, 0.8);
{/code}
Either of these examples will have a color that is opaque in some fashion. Consider the following:
If you're using IE see below:
{code type=css}
background-color:rgba(0, 0, 255, 1);
background-color:rgba(0, 0, 255, 0.8);
background-color:rgba(0, 0, 255, 0.6);
background-color:rgba(0, 0, 255, 0.4);
background-color:rgba(0, 0, 255, 0.2);
{/code}
This code using rgba allows us to create our desired effect.
Allows us to use these opaque colors, however, we can reach the same effect using the standard rgb color space or by using hexadecimal values.
Consider the following example:
We have the same effect using slightly different code in fact. We used the opacity property to create the fading squares.
{code type=css}
background-color:rgb(0, 0, 255); opacity:1.0;
background-color:rgb(0, 0, 255); opacity:0.8;
background-color:rgb(0, 0, 255); opacity:0.6;
background-color:rgb(0, 0, 255); opacity:0.4;
background-color:rgb(0, 0, 255); opacity:0.2;
{/code}
Main difference
The main difference between rgba + hsla and opacity is that we can apply opacity to any element we want instead of just backgrounds. This includes, but is not limited to, images and text.
This is some more text
As we can see, the text is fading with word. The first word is at 100% opacity, the second at 80%, third at 60%, etc... We denote these values in terms of decimals so 1 = 100%, 0.8 = 80%, etc...
Opacity
One really great thing about the opacity property is that you don't need to create an image sprite if you want an image to be slightly translucent before roll over and fully opaque during roll over. Here is an example of opacity:
{code type=css}
.chrome-opacity {
background:url (images/chrome.png) center center no-repeat;
height:64px;
width:64px;
opacity:0.8;
}
.chrome-opacity:hover {
background:url (images/chrome.png) center center no-repeat;
height:64px;
width:64px;
opacity:1.0;
}
{/code}
Using method above allows us to easily create semi-opaque images or text and allow them to become fully opaque on roll over or vice versa.
Note: IE 6 only supports the :hover pseudo-class on <a> tags only. Also, IE does not natively support this property where all of the other major browsers do.
To use this property with IE we'll need to create a conditional comment for all versions of IE like the following:
{code type=html}
{/code}
Note: that IE 6 and 7 do NOT extend support to the pseudo-class :hover on anything but <a> tags and therefore the hover will not work.
If you want to see working examples of the opacity property then please download the file!

opacity.zip
Size: 170.97 KB
CSS3 Colors
0You might be wondering what is so special about CSS3 colors and why they're even different considering that the color and background-color property and their values have not changed since CSS1 specification were released.
As set by CSS1 we can use the following for the color and background-color properties:
Color | Background-color |
---|---|
|
|
|
|
Aside from these standard mundane implementations of colors, CSS3 added a whole new color space: HSL.
HSL
HSL stands for Hue Satuation and Lightness. The break down is as follows:
Hue | Satuation | Lightness |
---|---|---|
Hue is the degree of a color wheel that goes from 0 to 360. Here as some general colors:
|
Satuation is the amount of color, or how "full" the color is. Here are some values:
|
Lightness is also a percentage but deals with how much white and black is added to the color. Here are some examples:
|
Here is an example of HSL:
Here is an example with RGB:
Here is an example with HEX:
The corresponding CSS for HSL colors is the following:
{code type=css}
background-color:hsl ([0-360], [x]%,[x]%);
background-color:hsl (360, 100% 50%);
background-color:hsl (133,85%, 61%);
{/code}
RGBA
There is nothing new about the RGB color space. We learned about the RGB color space in Basics of CSS Part 2 and we have seen many colors in the RGB color space and in hex format Color Reference.
Common examples of RGB would be the following:
{code type=css}
background-color:rgb(255, 0, 0); /*red*/
background-color:rgb(0, 255, 0); /*green*/
background-color:rgb(0, 0, 255); /*blue*/
{/code}
So what does the "a" mean in RGBA? The A stands for alpha which deals with transparency or the opacity of colors. The syntax for the alpha value will span from 0-1 in decimal form. For example:
{code type=css}
background-color:rgba(0, 0, 255, 0.4);
color:rgba(0, 0, 255, 0.8);
{/code}
The first example will set the opacity of pure blue to 40% and the second example will set the opacity of pure blue to 80%.
Alternatively, the RGB colors will be the following:
RGBA | RGB |
---|---|
background-color:rgba([color 1], [color 2], [color 3], [alpha]); background-color:rgba(0, 0, 255, 1); background-color:rgba(0, 0, 255, 0.8); background-color:rgba(0, 0, 255, 0.6); background-color:rgba(0, 0, 255, 0.4); background-color:rgba(0, 0, 255, 0.2); |
background-color:rgb([color 1], [color 2], [color 3]); background-color:rgb(0, 0, 255); background-color:rgb(50, 50, 254); background-color:rgb(101, 101, 254); background-color:rgb(152, 152, 254); background-color:rgb(203, 203, 254); |
These colors are not contingent on the color of the background. Since these colors have alpha transparency, they will show any colors or background images behind the elements. | These colors are contingent on the color of the background. If you wish for the element to be a certain color then you need to specify the color you wish to have. Will not show any color behind the element and will not show any background images behind the element because no alpha transparency exists. |
For example
Notice how above they were the same colors and now since we have a different color background the colors with rgba will allow the black background to show through where as the rgb colors will display their respective color values.
Which Browsers Support RGBA?
- Firefox 3.x+
- Safari 3+
- Safari 4+
- Google Chrome
- Opera 10.10+
- Flock 2.02
- Mobile Safari
- Blackberry Browser
IE Hack
Mission someone? Of course we are! We're missing lovely Internet Explorer and all of its versions. Luckly, there is a hack for IE.
{code type=html}
{/code}
We can use this hack as inline css or use in an internal or external style sheet. If you want a specific class selector or element to have an translucent color then use the hack for that element or class like the example above. If you want to use inline css then place the hack in the style attribute.
You might be wondering what #800000FF is. Think of this as #AARRGGBB where AA is the alpha value in two integers, RR are the red hexadecimals, GG are the green hexadecimals, and BB are the blue hexadecimals.
In order to covert our initial RGBA value to Hex we need to think interms of Hex to Decimal values.
Hex to Decimal
In order to convert Hex to Decimal we need to think mathematically. We'll start with an easy example:
Hex | Decimal |
---|---|
#ffffff | rgb(255, 255, 255) |
#0000ff | rgb(0, 0, 255) |
#ff00ff | rgb(255, 0, 255) |
How did we get these values of the top of our head? The solution is simple. Follow these steps from Jackson Hines's post on RGB to HEX and vice versa:
HEX to RGB (Ex: #a84fff)
- Take the first digit of the red part of the hex color. (ex: a)
- If this digit is a letter, replace with the letter of the alphabet and add 9. If it is not a letter, leave it. (ex: a = 1; 1 + 9 = 10)
- Take the second digit of the red part of the hex color. (ex: 8 )
- If this digit is a letter, replace with the letter of the alphabet and add 9. If it is not a letter, leave it. (ex: 8 )
- Divide this number by 16. (ex: 8 ÷ 16 = 0.5)
- Add the number you got in step two and the number you got in step 5. (ex: 10 + 0.5 = 10.5)
- Multiply this number by 16 to get the red value. (ex: 10.5 × 16 = 168)
- Repeat steps 1 through 8 with green and blue values. (ex: 168, 79, 255))
Alpha (#AA) & A
So what about alpha? Knowing the information we have obtained by Jackson's helpful article, we can convert our rgb value to hex and vice versa. If you wish not to do so much math and want to get results quickly, I recommend using Colorpicker.com.
#AARRGGBB to RGBA
Let us assume #660000FF is our #AARRGGBB color of choice. Convert #0000FF to RGB which will be rgb(0, 0, 255) and now time to convert #AA.
Following HEX to RGB conversion of #66:
- The first number is 6
- The second number is 6 ÷ 16 = 0.375
- The third number is the (first number + the second number) × 16 = 102
- 102 ÷ 255 = 0.4 for RGBA
If you don't want to that much math then you can use this conversion tool to convert any TWO hex characters to decimal or any series of Decimal characters. Once you have your decimal number, divide by 255 and you will have your RGBA number.
HSLA
Using the same principles as RGBA and HSL, just add the A to the end of the HSL values. For example
{code type=css}
background-color:hsla ([0-360], [x]%, [x]%, [0-1]);
background-color:hsla (133, 85%, 61%, 0.6);
{/code}
For more information an examples on the IE Hack for RGBA and HSLA, please download css3-colors.zip and open in IE.

css3-colors.zip
Size: 1.71 KB
CSS3 Text Effects
0Today we're going to talk about text effects and how they make a website become eye candy. If you, for example, visit atomicpages.net under the website management, website setup, and latest blog posts you will notice a slightly darker shadow right below the text. This is a text effect that makes a website less boring to look at.
text-shadow
The text-shadow property isn't at all new to CSS3. Originally, this property was going to be used with CSS2 which is what all of the Basics of CSS tutorials are based off of.
This property will allow us to create photoshop-like effects without having to use photoshop and saving the text as an image. Here is an example:
Notice how the font has a dark shadow as if the light were coming from about 11 o'clock.
The general syntax for the text-shadow property is as follows:
{code type=css}
text-shadow:[x-pos] [y-pos] [blur radius] [color];
text-shadow:2px 2px 2px #000;
{/code}
In the example above, the shadow will be 2px on the positive x-axis, 2px on the positive y-axis, and have a blur radius of 2px with a color of #000 (black).
Note: the [x-pos] and [y-pos] will take any positive or negative integer.
Which browsers support text-shadow?
Not all browsers today support the text-shadow property, here is a list of browsers that support this property:
Supported | Not Supported |
---|---|
|
|
word-wrap
Amazingly enough, the word-wrap was invented by Microsoft and has been implemented into CSS3. This property allows for long words in any given element to be broken and wrapped in a new line. Consider the following:
Without word-wrap
Width word-wrap
The values for word-wrap are normal and break-word.
{code type=css}
.wrap {word-wrap:break-word;}
.wrap {word-wrap:normal;} /*this is default*/
{/code}
In the example above, we used:
{code type=html}
Inthebrokwnwindowsargument,peoplearguethatthereisno
net gain from the creation of jobs.
Inthebrokwnwindowsargument,peoplearguethatthereisno
net gain from the creation of jobs.
{/code}
Using this method you can break larger words into smaller chunks.
Sources:
1: http://www.w3.org/TR/css3-text/
Introduction to CSS3
0As you probably know, CSS stands for Cascading Style Sheet and it used in place of HTML frames, and HTML tables. CSS was created to make web site creation easier and more pragmatic. If you have an external style sheet linked on all pages of your website, this will allow you to make changes all across the site with just a few changes.
Traditionally, you would have to open every page of you site and make the necessary changes. If you had a 20 page site and you decided to change you logo then you'd have to open every page and add that new logo into the pages. With CSS, however, you could change the logo just by changing the image name in your style sheet.
Versions of CSS
CSS1
CSS1 became a w3c recommendation in Dec 17th, 1996 and was last revised on Apr 11th, 2008. CSS1 included many CSS3 properties that are still used today such as margin, padding, border, and background. When CSS1 came out HTML 2.0 was the primary version of HTML. We're now on (X)HTML 4.01 as the standard.
CSS2
CSS2 included improvements on CSS1 such as a box-model, overflow, and aural style sheets for aria required screen readers.
CSS2.1
Many years later the w3c completed a major revision of CSS2 called CSS2.1 that became recommendation on September 8th, 2009. This includes many fixes on CSS2 and included many new values and new properties that made web design even more simple. At this time HTML 4.01, and XHTML 4.01 were standards at this point in time. When CSS 2.1 was birthed it began to phase out web sites made with HTML tables. CSS2 and CSS 2.1 allowed for a designer to make complex HTML table sites simpler and more practical to amend. This also gave way to very complex internet programs such as Drupal, Joomla, and WordPress (though they existed before 2008).
CSS3
As of March 3rd, 2010, CSS3 is still a working draft by the w3c. Some properties such as border-radius, text-shadow, and border-image are already supported by the latest versions of Chrome, Safari, Firefox, and Opera. For more information on CSS3 you can read the documentation here.
Note: A large sum of these selectors will NOT work in IE versions 5.5-8. To test and see which selectors are buggy and are not supported please visit css3.info's Selector Test. If you're using the latest versions of opera, chrome, safari, and Firefox then you needn't worry.
Some things we will cover
We will cover an extremely useful property called the "text-shadow" property. It can look like the following:
Text-Shadow
Border-Radius
and of course opacity/rgba:
Opacity
Sources:
- "Cascading Style Sheets, level 1", H. W. Lie and B. Bos, 17 December 1996, revised 11 January 1999 http://www.w3.org/TR/2008/REC-CSS2-20080411/
- "Cascading Style Sheets, level 2, CSS2 Specification", B. Bos, H. W. Lie, C. Lilley and I. Jacobs, 12 May 1998 (revised 11 April 2008),
http://www.w3.org/TR/2008/REC-CSS2-20080411/ - "Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification" B. Bos, H. Lie, I.H. http://www.w3.org/TR/CSS21/