【发布时间】:2016-04-18 14:20:05
【问题描述】:
我有什么
我有两个文本框,每个文本框都有一个随焦点变化的背景图像。所有背景图像均来自一个精灵表。
我需要什么
我需要限制精灵表的显示量,因为文本框大于我希望显示的背景量。
重要
编辑标记不是一种选择。我需要一个基于 CSS 的解决方案。
我的代码
#foo,
#bar {
background-position: left center;
background-repeat: no-repeat;
background-size: 100px 100px;
background-image: url("http://s30.postimg.org/5huu7u8ip/test.png");
padding: 0 1em;
padding-left: 50px;
font-size: 17px;
height: 3em;
}
#foo {
background-position: 0px 0px;
}
#bar {
background-position: 0px -50px;
}
#foo:focus {
background-position: -50px 0px;
}
#bar:focus {
background-position: -50px -50px;
}
<p>Click into and out of each box to toggle default and focus states:</p>
<p>
<label for="foo">
<input type="text" size="20" value="" class="input" id="foo" placeholder="foo" name="foo">
</label>
</p>
<p>
<label for="bar">
<input type="text" size="20" value="" class="input" id="bar" placeholder="bar" name="bar">
</label>
</p>
使用上面的实时示例,绝不应该出现多个图标显示的情况。焦点很好,问题出现在文本框的默认状态上。
【问题讨论】:
标签: html css background sprite-sheet