2

从本质上讲,标题说明了一切。

div {
  border-radius: 4px;
  background-image: url(IMAGE1.PNG), url(IMAGE2.PNG);
  box-shadow: 0 0 10px rgba(0,0,0,0.75), inset 1px 1px 2px #fff, inset -1px -1px 1px #777;
}

本质上,我希望 image1 将默认属性保持为典型背景,但我希望将 image2 设置为等效于background-size: cover;

4

1 回答 1

4

background-size也接受多个值。

background-size: auto, cover;

var pattern = Trianglify({
  height: 300,
  width: 300,
  cell_size: 40,
});

var div = document.getElementsByTagName('div')[0];

div.style.backgroundImage = "url('https://i.stack.imgur.com/955qe.png'), url('" + pattern.png() + "')";
div {
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.75), inset 1px 1px 2px white, inset -1px -1px 1px #777;
  background-position: center;
  background-repeat: no-repeat;
  background-size: auto, cover;
  height: 140px;
  width: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/0.2.0/trianglify.min.js"></script>

<div></div>

于 2015-04-21T06:55:20.463 回答