CSS 如何在css中应用渐变颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3044853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:13:44  来源:igfitidea点击:

How to apply gradient color in css?

backgroundcssgradient

提问by udaya

I want to use gradient color as my page background how do I apply css to get gradient background?

我想使用渐变颜色作为我的页面背景如何应用 css 来获取渐变背景?

回答by Ryano

CSS 3 supports gradientsbut this won't be supported by all browsers (eg IE6).

CSS 3 支持渐变,但并非所有浏览器(例如 IE6)都支持。

But you could do this, which I think is pretty similar to the previous answer:

但是你可以这样做,我认为这与之前的答案非常相似:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
    body {
        padding:0px;
        margin:0px;
    }
    div#bg {
        background: url(http://www.khiba.com/PSP/FALL01/Testgrad.jpg) repeat-x;
        height:600px;
    }
</style>
</head>

<body>
<div id="bg">
</div>
</body>
</html>

回答by 1s2a3n4j5e6e7v

if you want your site to be compatible with all browsers, you can use this :

如果您希望您的网站与所有浏览器兼容,您可以使用:

background-image: url(someurl.gif);
background-repeat: repeat-x;

the someurl.gif image should contain the gradient that you want. Have it as a very small piece of image and you can extend it with repeat-x or repeat-y. whichever you prefer.

someurl.gif 图像应包含您想要的渐变。把它作为一个非常小的图像,你可以用repeat-x 或repeat-y 来扩展它。无论你喜欢哪个。