【发布时间】:2019-04-09 03:42:30
【问题描述】:
我正在尝试从这张图片(pic 2)中重复这部分(pic 1 是箭头位)。但是,它不需要重复图像的那个端口。它只显示整个图像。我该如何解决这个问题(并且仍然继续使用图像精灵)。
图片精灵的宽度为134px,高度为44px
body {
padding: 0;
margin: 0;
}
.test-box {
position: relative;
display: inline-block;
width: auto;
height: 14px;
line-height: 14px;
font-family: arial;
font-size: 9px;
color: #000;
background: url("https://www.w3schools.com/css/img_navsprites.gif") -84px -18px repeat-x;
}
<div class="test-box">this is a text message</div>
如果我要使用普通图像(不是图像精灵),那么它可以工作。但我想使用图像精灵。例如,当它不是图像精灵时它可以工作
body {
padding: 0;
margin: 0;
}
.test-box {
position: relative;
display: inline-block;
width: auto;
height: 14px;
line-height: 14px;
font-family: arial;
font-size: 9px;
color: #000;
background: url("https://i.imgur.com/PhEZLTm.png") repeat-x;
}
<div class="test-box">this is a text message</div>
【问题讨论】:
-
@cjl750 不起作用。在我提出这个问题之前已经看过这篇文章
-
这个问题的答案的重点是,纯粹用 CSS 做你想做的事是不可能的;您必须以特定的方式设置您的图像精灵才能做到这一点。您在此示例中使用的图像将不起作用,因为它没有设置为允许重复。
标签: html css background repeat