我知道我可以使用 imagebutton 作为图像按钮。但我想使用 css sprites 来减少下载的图像数量。所以我想通过 css 类将普通按钮分配给图像。但好像不起作用。
这是我尝试的代码和图像
按钮代码
<asp:Button ID="btn1" CssClass="filter-tr" runat="server" />
<br />
<br />
<br />
<asp:Button ID="Button2" CssClass="filter-en" runat="server" />
<br />
<br />
<br />
<asp:Button ID="Button3" CssClass="flying" runat="server" />
<br />
<br />
<br />
<asp:Button ID="Button1" CssClass="fire" runat="server" />
这里是 css 类代码
.filter-tr, .filter-en, .flying, .fire
{ display: block; background: url('images/image1.png') no-repeat; }
filter-tr { background-position: -0px -0px; width: 60px; height: 25px; }
filter-en { background-position: -0px -25px; width: 60px; height: 25px; }
flying { background-position: -0px -50px; width: 44px; height: 16px; }
fire { background-position: -0px -66px; width: 44px; height: 16px; }
但是这样就可以了
.filter-tr { display: block; background: url('images/image1.png') no-repeat; background-position: -0px -0px; width: 60px; height: 25px; border-width:0px; }
最佳答案
我要做的第一件事是将后台 URL 设置为使用绝对位置:
.filter-tr, .filter-en, .flying, .fire
{ display: block; background: url('/images/image1.png') no-repeat; }
没有更多信息,这就是我能提供的所有帮助。
编辑
之前就应该注意到的。类名前面都需要有一个.
:
.filter-tr { background-position: -0px -0px; width: 60px; height: 25px; }
.filter-en { background-position: -0px -25px; width: 60px; height: 25px; }
.flying { background-position: -0px -50px; width: 44px; height: 16px; }
.fire { background-position: -0px -66px; width: 44px; height: 16px; }
关于c# - 通过 css 类分配 ASP.net 按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5110952/