Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a vertical gradient background to work in all browsers?

Tags:

jquery

css

If you were to get a vertical gradient background starting from white down to some shade of grey, how would you do it?

like image 804
Sussagittikasusa Avatar asked Jan 25 '26 05:01

Sussagittikasusa


2 Answers

You can do it with CSS, check out this link.

It uses CSS3 properties in good browsers, and IE's propriety filter property when using IE.

CSS

#gradient {
    background: #FFFFFF; /* old browsers */
    background: -moz-linear-gradient(top, #FFFFFF 0%, #CCCCCC 100%); /* firefox */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FFFFFF), color-stop(100%,#CCCCCC)); /* webkit */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FFFFFF', endColorstr='#CCCCCC',GradientType=0 ); /* ie */
}

...produces...

gradient

like image 195
alex Avatar answered Jan 28 '26 14:01

alex


background: url('vertical-gradient.jpg') repeat-x #eee

I'd recommend repeating your gradient image across the x-axis, then having a solid color that matches the bottom gradient color. In my example, that would be #eee.

The end result is something like this:

AAAAAA <- start gradient image
BBBBBB
CCCCCC
DDDDDD
EEEEEE <- end gradient image
EEEEEE <- start solid color until end of document
like image 25
Ben Avatar answered Jan 28 '26 15:01

Ben