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

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;等效的值

最佳答案

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>

关于html - 两个大小不同的DIV背景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29764939/

10-15 12:28