Archive for March, 2011

CSS3 Pie (Make CSS3 work in IE)

Posted on: March 30th, 2011 by Lisa 1 Comment

No matter how irritating it is to have to worry about making your designs work in Internet Explorer, if you want to be a decent web designer, you need to account for IE. Over half of web users still use some version of it, and unless you know the web audience targeted won’t be using IE, you should try to make sure your website looks at least nice and acceptable in IE. It does not need to look exactly the same, however.

A great little plug-in to bridge the IE gap and bring a few of the important CSS3 properties to that browser is called CSS3 Pie. It makes the following properties work in IE browsers:

  • border-radius
  • gradient (linear only)
  • box-shadow
  • multiple background images

CSS3 Pie is a simple download with one file that you add to the home directory of your website. It can actually be added in a subdirectory, but if you don’t put it in your home directory, the url in the snippet will need to be changed.

Once you have added this file to the root directory, all you need to do to make the CSS work is the following snippet of code after your other CSS3 code:
behavior: url(PIE.htc);
position: relative; /* This fixes a z-index problem, but may not be necessary */

The path of your url may need to be different. It is important that the path is correct relative to your HTML pages, and not your CSS page. I have had a little bit of trouble getting CSS3PIE to work correctly for all the sup pages when using Word Press. Putting PIE in root directory and using a path of (/PIE.htc) is working best for me with WordPress.

Explanation

CSS3 Pie is an easy to use utility, but you may have issues getting it to work. My experience has been good as long as I use relative positioning.

Sometimes if you don’t add the line making the selector have relative positioning, the objects you are applying the CSS3 property will disappear. There may be times when using relative positioning won’t work for you. If that is the case, please read the troubleshooting page for more explanation on common issues with CSS3Pie.

Always test your work on an Internet Explorer browser, versions 6, 7 or 8, to make sure that things are working the way you want.

CSS3Pie does not work with IE9, but those CSS3 properties already work in IE9.

Be sure to check out the Known Issues page, if you are having any trouble. There is also a User Forum for additional help. Overall, the entire web-site is full of great info and help, so make sure to explore if you want to learn more.

/*****************************************************************************************/

CSS3 Vendor Prefixes

Posted on: March 24th, 2011 by Lisa No Comments
-moz-     /* Firefox and other browsers using Mozilla's browser engine */
-webkit-  /* Safari, Chrome and browsers using the Webkit engine */
-o-       /* Opera */
-ms-      /* Internet Explorer (but not always) */ 

Explanation

These browser prefixes are needed as the browsers experiment and test out their implementations of the newer CSS3 properties. Sometimes all the prefixes are not always needed, but it usually does not hurt to include them, as long as you make sure to put the non-prefixed version last.

-moz-border-radius: 10px; 
-webkit-border-radius: 10px; 
-o-border-radius: 10px; 
border-radius: 10px; 

There are several reasons why this is important, but I’m not going to get into that here. Just make it a rule to always include the non-prefixed version and put it at the end.

Some properties are so far along in development, that some browsers are dropping the prefix. Border-radius is one property that is pretty well developed at this point. The latest versions of major browsers all seem to support it without the vendor-prefixes. Keeping them in the code, however, allows you to make sure users who don’t update their browsers, will still be served.

Internet Explorer

Internet Explorer 9 supports many (but not all) of the favorite CSS3 properties. You can use border-radius without any vendor-prefix, for example.

For IE versions 6-8 (which includes almost half of all users browsing the web, unfortunately) you need to to make sure your design works OK without the CSS3. For three properties: border-radius, linear-gradient, and box-shadow, you can use CSS3Pie, which I will be discussing in my next post. It is a great little file you can add to your home directory (based on javascript) which makes these properties work in Internet Explorer versions 6-8.

If you install it in your site, you can add this code after your other defintions:
behavior: url(/PIE.htc);

/*****************************************************************************************/

Engraved Text with CSS

Posted on: March 23rd, 2011 by Lisa 5 Comments

An engraved text effect (where text appears lower than the surface) can be done with the CSS3 property text-shadow.

You can add this CSS to any selectors with text where you want this effect.

/* Darker text on medium background */
color: #333;
background-color: #666;
text-shadow: 0px 1px 0px rgba(255,255,255,.5); /* 50% white from bottom */

/* Medium text on lighter background */
color: #666;
background-color: #aaa;
text-shadow: 0px -1px 0px rgba(0,0,0,.5); /* 50% black coming from the top */

Explanation

The parameters of text-shadow are listed below in the order they must appear in your CSS.

Horizontal Offset

For this effect, leaving the horizontal offset at 0 allows the shadow to come from one direction only (vertically) which provides a cleaner look and better effect.

Vertical Offset

When using the darker text on a medium background, it usually works best to use a lighter shadow coming from below. This makes the text look like it is lower than the surface. When using lighter colors, a darker shadow coming from above, gives the same effect. Making the shadow come from above is achieved by using a -1 in the Vertical offset.
text-shadow: 0px -1px 0px rgba(0,0,0,.5);

Blur Radius

You don’t want any blur on the shadow for this effect, so the value is 0.

Color

The last value is the color of the shadow. I am using RGBA colors, which is a combination of the R, G, and B values (you can get these from the Photoshop Color Picker) and the Alpha Transparency. All browsers that support text-shadow also support RGBA values.

You don’t need to use RGBA values; you could try a medium-dark grey color in this example instead. However, using transparency for the shadow, will allow some of the original color to shine through and generally provides a nicer effect. This is especially useful when you are using this effect on colors.

Browser Support

All recent versions of Safari, Firefox, Chrome, and Opera support both text-shadow and RGBA colors. Internet Explorer does not. IE9 does support RGBA colors, but as far as I can tell (as of today) it does not support text-shadow, unfortunately. If you view the demo page with IE, you won’t see the effect.

There is a filter property than can be used on Internet Explorer, that sometimes works, but sometimes produces ugly results. You can experiment and try to find some values that work.

If you would like to read more about using IE shadows to try to make it work, try these articles: Drop Shadow on all Browsers and RGBA Generator of IE

To support IE browsers, you must choose from the following:

  1. Make sure the text looks fine without the Inset effect. This means making sure there is enough contrast between the text color and background color.
  2. Create an image of your inset text headers, and apply them as background-images in style sheet specific to IE only. If you do this, you may decide to skip the CSS solution altogether. However, CSS solutions mean less images to download, so there is a savings for using CSS when you can.
  3. Try using the filter commands for IE, but make sure to text and see if things still look OK.

What text will look like in IE. Make sure things are still legible.

Two Part Shadows

You can sometimes get even better results by using two text-shadows on the text – one dark shadow and one light shadow. You can specify two different shadows on your elements by separating them with a comma. I have found that two shadows are not usually necessary when using greys, but they can be useful with colors.

Here is an example in color with just one shadow:
text-shadow: 0px 1px 0px rgba(255,255,255,.5);

In this second example, I used two shadows, and different opacities, with better results.
text-shadow: 0px 1px 0px rgba(255,255,255,.3), 0px -1px 0px rgba(0,0,0,.7);

Note: The above examples are screen shots. The quality is not as clear as it actually looks on screen, so be sure to look at the demo page to see the effect. (Of course, the demo won’t work in IE.)

/*****************************************************************************************/

More with border-radius

Posted on: March 8th, 2011 by Lisa 1 Comment

The border-radius command can be used in many different ways. Using a single value creates rounded corners of the same size, but the property can also be used with different values for each corner, allowing you to create Tabs or other interesting shapes.

The syntax for creating corners of different sizes, can be complex, but there is a shorthand version, which I always use instead. The order of the corners starts with the top-left corner and moves clockwise, ending with bottom-left.

/* I'm adding "px" after 0 so it's easy to change values, but it's not needed for 0 */
-moz-border-radius: 20px 20px 0px 0px;
-webkit-border-radius: 20px 20px 0px 0px;
border-radius: 20px 20px 0px 0px;

Explanation

Creating other shapes is just as simple. You can make any of the 4 corners rounded and with unique values.

.opposite { 
  width: 100px; height: 100px;
  background-color: #A0DE21; 
  -moz-border-radius: 20px 0px 20px 0px;
  -webkit-border-radius: 20px 0px 20px 0px;
  border-radius: 20px 0px 20px 0px;
}

If you take the rounded corner to the extreme, you can create a leaf shape. Also, note the shorthand. When both sets of opposite corners have the same values, you only have to type 2 numbers once. (’100px 0′, instead of ’100px 0 100px 0′.)

.leaf { 
  width: 100px; height: 100px;
  background-color: #A0DE21; 
  -moz-border-radius: 100px 0px;
  -webkit-border-radius: 100px 0px;
  border-radius: 100px 0px;
}

Finally, you can make every corner have a different value, creating unique shapes.

.odd { 
  width: 100px; height: 100px;
  background-color: #A0DE21; 
  -moz-border-radius: 50px 30px 10px 0px;
  -webkit-border-radius: 50px 30px 10px 0px;
  border-radius: 50px 30px 10px 0px;
}

/*****************************************************************************************/

CSS3 Rounded Corners

Posted on: March 4th, 2011 by Lisa No Comments

If you want to create rounded corners without images, you can by using CSS3. The border-radius property is one of the best supported CSS3 properties and can be used today. You can even get it to work in Internet Explorer versions 6-8 with a plug-in. As with most CSS3 properties, you need to target all the major browsers by using vendor-specific prefixes.

-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

rounded corners

Explanation

A simple DIV with a class of “shape” to give it dimension and color.

<div class="shape"></div>width: 100px;
height: 100px;
background-color: #5d8d89;

Now I’ve added the border-radius property to round the corners.

-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

rounded corners

If you want to make a circle you can use a radius equal to half the width. (In this case, that’s 50px.)

-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;

Notes

  • Put the vendor specific prefixes first. When CSS3 is implemented across all browsers consistently, the border-radius property at the end will be the one used.
  • Smaller numbers in the radius mean less of a rounded corner. Larger numbers will give a larger curve.
  • border-radius is well supported in all the latest versions of the modern browsers. IE9+, Chrome10+ and Opera 10.5+ all support the regular non-prefix version. You should still use -moz and -webkit versions for Firefox and Safari.
  • It is possible to make rounded corners work in earlier versions of Internet Explorer. I useĀ CSS3 Pie to make this happen. I will explain that another day. It is simple enough to get to work (although you may need to read the forum for some help.) Check out the link if you want to try it. If you don’t use CSS3Pie or another method of showing rounded corners, IE users will just get regular rectangles instead. It is best to make sure your design still works with the rectangles, since many users still are using IE. It is generally considered fine to allow your site to look different in different browsers. This is called “graceful degradation” or “progressive enhancement” depending on how you look at it. Twitter is a good example of a web site that uses this philosophy. All of the rounded corners are just regular rectangles when viewing the web-site with IE, and it looks fine and professional without them.

/*****************************************************************************************/