CSS gradients

Gradient

This is an easy way to change the color of your gradient, using png and body background color.

Step 1: Create a gradient png

- Open Photohop
- file > new
- 17 x 800 pixels
- make a gradient from white to transparent
- file > save as > PNG

Step 2: The css

IE is the big problem with PNG, so we have to use the filter hack.

body {
margin: 0;
padding:0;
background: #5788b2;
}

To change the color of your gradient, you only have to change the background color.

#gradient {
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='gradient.png', sizingMethod='scale');
width:100%;
height:800px;
}

This filter is for IE, the height is to show the gradient, you can delete it because the div will follow your content.

*>#gradient {
background:url(gradient.png) top left repeat-x;
}

This ID for the other browers, IE can’t read *>.

Step 3: HTML

<div id="gradient">
Gradient flow
</div>

The result

With only changing the background color, you have a nice gradient. You can change the gradient PNG for some other gradient effects. The only downside is that you have to put every div inside ID gradient on position relative and a higher z-index to make your links work.

I have tested it in:
- Firefox (mac en pc)
- IE 6
- IE 7
- Safari

View the result here

This entry was posted in CSS by Sibran. Bookmark the permalink.

About Sibran

he Name Sibran is a boy’s name. The origin of the baby name Sibran is Breton with the meaning(s) depending on Gender/Origin being Breton- From Cyprus. Sibran has the following similar or variant Names: Sybran. I am a multimedia developer specialized in HTML/CSS, web 2.0, web standards, Google Custom Search, Search engine optimization. I like the blue water between the big islands with all his/her mysteries, it’s the only place in the world that is still unknown… and because that’s the only place where it never rains.

One thought on “CSS gradients

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>