简体   繁体   English

不可重复的背景图片和渐变

[英]no-repeat background image and gradient same time

How to use no-repeat background image and gradient same time 如何同时使用无重复背景图像和渐变

// this only show some gradient
background-image: url('../../imgs/0/cart.png') no-repeat left center,-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(238,238,238,1)), color-stop(100%,rgba(204,204,204,1))); /* Saf4+, Chrome */

//This is ok
background-image: url('../../imgs/0/cart.png'),-webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(238,238,238,1)), color-stop(100%,rgba(204,204,204,1))); /* Saf4+, Chrome */

"url('../../imgs/0/cart.png') no-repeat left center" is not a valid value of background-image property. “ url('../../ imgs / 0 / cart.png')无重复的左中心”不是background-image属性的有效值。 It's a valid value of background shorthand. 这是背景速记的有效值。

There are two ways to specify multiple backgrounds in CSS: as a list of shorthand properties, like 有两种方法可以在CSS中指定多个背景:作为速记属性的列表,例如

    background: url('http://placekitten.com/256/150') no-repeat left center, linear-gradient(to bottom, rgba(238,238,238,1), rgba(204,204,204,1)) no-repeat;

or like separate list of each sub-property values, like 或每个子属性值的单独列表,例如

    background-image: url('http://placekitten.com/256/150'), -webkit-gradient(linear, 0 100%, 0 0, from(rgba(238,238,238,1)), to(rgba(204,204,204,1)));
    background-image: url('http://placekitten.com/256/150'), -webkit-linear-gradient(rgba(238,238,238,1), rgba(204,204,204,1));
    background-image: url('http://placekitten.com/256/150'), linear-gradient(rgba(238,238,238,1), rgba(204,204,204,1));
    background-repeat: no-repeat, no-repeat;
    background-position: left center, left top;
    background-size: auto, 100% 100%;

I'd suggest the latter one because it doesn't require to duplicate background-repeat etc. values for all prefixed versions of gradient. 我建议使用后者,因为它不需要为所有前缀的渐变版本重复背景重复等值。

you need to set same amount of values to each imge/gradient you set in BG. 您需要为在BG中设置的每个图像/渐变设置相同数量的值。 http://codepen.io/gcyrillus/pen/jfiyz http://codepen.io/gcyrillus/pen/jfiyz

html {
  height:100%;
}
body {
  min-height:100%;
}
html  {
  background:#555;
  text-align:center;
  background:
    linear-gradient(-40deg,#222,transparent,#111) center repeat, 
    linear-gradient(40deg,#222,transparent,#111) center repeat, 
    linear-gradient(-40deg,#222,transparent,#111) center repeat, 
    linear-gradient(40deg,#222,transparent,#111) center repeat ,
    url(http://lorempixel.com/500/500/abstract/2)  center repeat
    ;
  background-size:95% 85%;
  background-position:center;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM