CSS如何多个背景+渐变?

时间:2012-11-29 08:04:03

标签: html css

我从css graident生成器获得了这个代码,它在渐变的底部是透明的

background: -moz-linear-gradient(top,  rgba(248,246,247,1) 0%, rgba(248,246,247,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(248,246,247,1)), color-stop(100%,rgba(248,246,247,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(248,246,247,1) 0%,rgba(248,246,247,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(248,246,247,1) 0%,rgba(248,246,247,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(248,246,247,1) 0%,rgba(248,246,247,0) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(248,246,247,1) 0%,rgba(248,246,247,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f8f6f7', endColorstr='#00f8f6f7',GradientType=0 ); /* IE6-9 */

现在我想在渐变背景上添加背景

background: url('../images/letter_head.png') left top repeat-x, #f8f6f6;

我如何将它们组合在一起?

2 个答案:

答案 0 :(得分:0)

CSS

.bg{
    width:800px; height:750px;
    background: #38BAC9 url(http://www.google.com/logos/2012/india12-hp.jpg) 10% no-repeat;
    background:url(http://www.google.com/logos/2012/india12-hp.jpg) center no-repeat, -webkit-gradient(linear, 0% 0%, 0% 100%, from(#57BEED), to(#38BAC9));
    background:url(http://www.google.com/logos/2012/india12-hp.jpg) center no-repeat, -moz-linear-gradient(top, #57BEED 0%, #38BAC9 100%);    
}​

<强> DEMO

查看此链接以获取更多信息

http://userinterfacehome.blogspot.in/2012/09/css-multiple-background.html

答案 1 :(得分:0)

只需将图片的网址添加到您的每个规则中。

background: url(someurl), -moz-linear-gradient(top,  rgba(248,246,247,1) 0%, rgba(248,246,247,0) 100%); /* FF3.6+ */

或者,如果您不想在每个规则中添加url(etc),则只需指定一个background-image规则:

background: -moz-linear-gradient(top,  rgba(248,246,247,1) 0%, rgba(248,246,247,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(248,246,247,1)), color-stop(100%,rgba(248,246,247,0))); /* Chrome,Safari4+ */
...
background-image:url("someurl");