我如何使用CSS3渐变为我的背景颜色,然后应用背景图像应用某种轻透明纹理?
当前回答
如果你有奇怪的错误下载背景图像使用W3C链接检查:https://validator.w3.org/checklink
以下是我使用的现代mixin (credit: PSA:不要使用梯度生成器):
.buttonAkc
{
.gradientBackground(@imageName: 'accept.png');
background-repeat: no-repeat !important;
background-position: center right, top left !important;
}
.buttonAkc:hover
{
.gradientBackgroundHover('accept.png');
}
.gradientBackground(@startColor: #fdfdfd, @endColor: #d9d9db, @imageName)
{
background-color: mix(@startColor, @endColor, 60%); // fallback
background-image: url("@{img-folder}/@{imageName}?v=@{version}"); // fallback
background: url("@{img-folder}/@{imageName}?v=@{version}") no-repeat scroll right center, -webkit-linear-gradient(top, @startColor 0%, @endColor 100%) no-repeat scroll left top; // Chrome 10-25, Safari 5.1-6
background: url("@{img-folder}/@{imageName}?v=@{version}") no-repeat scroll right center, linear-gradient(to bottom, @startColor 0%, @endColor 100%) no-repeat scroll left top;
}
.gradientBackgroundHover(@imageName)
{
.gradientBackground(#fdfdfd, #b5b6b9, @imageName);
}
其他回答
如果你必须在IE 9 (HTML 5 & HTML 4.01 Strict)中让渐变和背景图像一起工作,添加以下属性声明到你的css类中,它应该可以做到:
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#000000', endColorstr='#ff00ff'), progid:DXImageTransform.Microsoft.AlphaImageLoader(src='[IMAGE_URL]', sizingMethod='crop');
注意,您使用了filter属性,并且progid有两个实例:[val],在用分号关闭属性值之前,用逗号分隔。这是小提琴。还要注意,当你看小提琴时,梯度延伸到圆角之外。我没有解决其他不使用圆角。还要注意,当在src [IMAGE_URL]属性中使用相对路径时,该路径是相对于文档页面而不是css文件(参见源代码)。
这篇文章(http://coding.smashingmagazine.com/2010/04/28/css3-solutions-for-internet-explorer/)引导我找到了这个解决方案。它对特定于ie的CSS3非常有帮助。
我的解决方案:
background-image: url(IMAGE_URL); /* fallback */
background-image: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0.7) 100%), url(IMAGE_URL);
我想让跨度按钮与背景图像,背景渐变组合。
http://enjoycss.com/帮助我完成工作任务。只是我必须删除一些自动生成的额外CSS。但这真的是一个很好的网站,建立你的草稿工作。
#nav a.link-style span {
background: url("../images/order-now-mobile.png"), -webkit-linear-gradient(0deg, rgba(190,20,27,1) 0, rgba(224,97,102,1) 51%, rgba(226,0,0,1) 100%);
background: url("../images/order-now-mobile.png"), -moz-linear-gradient(90deg, rgba(190,20,27,1) 0, rgba(224,97,102,1) 51%, rgba(226,0,0,1) 100%);
background: url("../images/order-now-mobile.png"), linear-gradient(90deg, rgba(170,31,0,1) 0, rgba(214,18,26,1) 51%, rgba(170,31,0,1) 100%);
background-repeat: no-repeat;
background-position: 50% 50%;
border-radius: 8px;
border: 3px solid #b30a11;
}
我希望这是跨浏览器的:
(修改了从渐变编辑器的基础,黑色到透明的垂直渐变在图像的顶部)
background-image: url('YOURIMAGE.JPG');
background-image: -moz-linear-gradient(left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%),url('YOURIMAGE.JPG'); /* FF3.6-15 */
background-image: -webkit-linear-gradient(left, rgba(0,0,0,1) 0%,rgba(0,0,0,0) 100%),url('YOURIMAGE.JPG'); /* Chrome10-25,Safari5.1-6 */
background-image: linear-gradient(to right, rgba(0,0,0,1) 0%,rgba(0,0,0,0) 100%),url('YOURIMAGE.JPG'); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#000000', endColorstr='#00000000',GradientType=1 ), progid:DXImageTransform.Microsoft.AlphaImageLoader(src='YOURIMAGE.JPG', sizingMethod='crop'); /* IE6-9 */
我用那种方法解决问题。我在HTML中定义渐变,在主体中定义背景图像
html { Background-image: -webkit-gradient(线性,左下,右上,颜色停止(0.31,rgb(227, 227, 227)),颜色停止(0.66,rgb(199, 199, 199)),颜色停止(0.83,rgb(184, 184, 184)); 背景-图像:-moz-linear-gradient(左下,rgb(227, 227, 227) 31%, rgb(199, 199, 199) 66%, rgb(184, 184, 184) 83%); 高度:100% } 身体{ 背景:url(“http://www.skrenta.com/images/stackoverflow.jpg”); 高度:100% }