使用一种解决方案,element()但支持率仍然很低。诀窍是创建一个基本的 div,其中包含一个用作背景图案的图像,然后您只需调整该 div 内的填充。
这是一个仅适用于 Firefox 的示例:
#image {
padding: 0 10px 15px 0; /* control the gap here */
display:inline-block;
}
.main {
height: 100vh;
background: -moz-element(#image) 0 0/200px auto;
}
body {
margin: 0;
}
<div class="main">
</div>
<div style="height:0;overflow:hidden;">
<div id="image">
<img src="https://picsum.photos/id/1024/300/300">
</div>
</div>

宽度 SVG 你可以尝试如下:
svg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<pattern id="bgimg" x="0" y="0" width="120" height="130" patternUnits="userSpaceOnUse">
<image xlink:href="https://picsum.photos/id/1055/100/100.jpg" x="0" y="0" height="100" width="100" />
</pattern>
</defs>
<rect x="0" y="0" width="10000" height="10000" fill="url(#bgimg)" />
</svg>
您只需控制图案元素的宽度/高度即可控制距离。在上面我们有100x100一个矩形内的图像,因此每个图像之间的120x130距离2030
交互式示例:
$("#x").on("change", function() {
$('#bgimg').attr("width",100+parseInt($(this).val()))
});
$("#y").on("change", function() {
$('#bgimg').attr("height",100+parseInt($(this).val()))
});
svg {
position: fixed;
top: 50px;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<pattern id="bgimg" x="0" y="0" width="100" height="100" patternUnits="userSpaceOnUse">
<image xlink:href="https://picsum.photos/id/1055/100/100.jpg" x="0" y="0" height="100" width="100" />
</pattern>
</defs>
<rect x="0" y="0" width="10000" height="10000" fill="url(#bgimg)" />
</svg>
<input type="range" min="0" max="100" step="5" id="x" value="0">
<input type="range" min="0" max="100" step="5" id="y" value="0">