开发者

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

开发者 https://www.devze.com 2023-01-25 17:24 出处:网络
If you were to get a vertical gradient background starting from white down to some s开发者_如何学Pythonhade of grey, how would you do it?You can do it with CSS, check out this link.

If you were to get a vertical gradient background starting from white down to some s开发者_如何学Pythonhade of grey, how would you do it?


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...

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


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


The only way to make it work in literally all browsers is to use an image.

0

精彩评论

暂无评论...
验证码 换一张
取 消