c# - 通过 css 类分配 ASP.net 按钮图像

标签 c# asp.net css class button

我知道我可以使用 imagebutton 作为图像按钮。但我想使用 css sprites 来减少下载的图像数量。所以我想通过 css 类将普通按钮分配给图像。但好像不起作用。

这是我尝试的代码和图像

enter image description here

按钮代码

    <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/

相关文章:

c# - 如何从 LINQ 查询中获取生成的 Lucene 查询

c# - 将设备到云消息从 Azure IoT 中心路由到 Azure Blob 存储

.net - 为什么 Visual-Studio 开发服务器会自动分配端口号?

html - 如何使html表格响应?

c# - 如何将字符串发送到 com 接口(interface)中的方法?

android - 如何将数据从 android 发送到 SQL Server 2008?

asp.net - Silverlight 4 - 使用 Windows 身份验证的 401.2 响应

javascript - 浏览器重新格式化我的 HTML,导致不同的外观

html - 如何处理网页中不同长度的语言?

c# - 带参数的 void 方法和不带参数的返回值方法?