带背景图像的禁用 ASP.NET Linkbutton 样式

发布于 2024-12-08 22:53:09 字数 692 浏览 3 评论 0原文

我正在使用一个简单的 ASP.NET linkbutton 控件。

<asp:LinkButton ID="LinkButtonDelete" runat="server" CssClass="linkButtonDelete">Delete</asp:LinkButton>

我使用以下 css 定义设置此按钮的样式:

.linkButtonDelete:link
{
    background: transparent url(/../images/btnRegular.png) no-repeat scroll 0 0 !important;
}
.linkButtonDelete:hover
{
background: transparent url(/../images/btnHighlight.png) no-repeat scroll 0 0 !important;
}

这就是问题:如果我禁用链接按钮 (LinkBut​​tonDelete.Enabled = false;),然后将鼠标悬停在链接按钮上,背景图像将显示 btnHighlight.png (而不是 btnRegular.png )。我在 IE9 和 Chrome 中对此进行了测试。效果一样。

我是否有机会仅使用 CSS 应用“禁用”样式(请不要使用 Javascript!)?

谢谢

I am using a simple ASP.NET linkbutton control.

<asp:LinkButton ID="LinkButtonDelete" runat="server" CssClass="linkButtonDelete">Delete</asp:LinkButton>

I am styling this button with the following css definitions:

.linkButtonDelete:link
{
    background: transparent url(/../images/btnRegular.png) no-repeat scroll 0 0 !important;
}
.linkButtonDelete:hover
{
background: transparent url(/../images/btnHighlight.png) no-repeat scroll 0 0 !important;
}

And here is the problem: If I disable the linkbutton (LinkButtonDelete.Enabled = false;) and then hover over the linkbutton, the background image shows btnHighlight.png (instead of btnRegular.png). I tested this in IE9 and Chrome. Same effect.

Is there any chance I can apply a "disabled" style with CSS only (please no Javascript!)?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黒涩兲箜 2024-12-15 22:53:09

我保留我的另一个答案,因为它也可以工作,但如果你想要一个纯粹的 CSS 解决方案,请查看从 CSS 2.1 开始支持的属性选择器。假设 ASP.NET 设置了禁用属性,您可以添加如下内容:

.linkButtonDelete[disabled="disabled"]:hover
{
background: something else;   
}

I'm keeping my other answer because it would work as well, but if you want a purely CSS solution, look into Attribute Selectors which are supported starting with CSS 2.1. Assuming ASP.NET sets the disabled attribute, you could add something like so:

.linkButtonDelete[disabled="disabled"]:hover
{
background: something else;   
}
寂寞花火° 2024-12-15 22:53:09

听起来它的行为就像你告诉它的那样。它显示悬停。如果您不希望它显示悬停,那么当您禁用按钮时,听起来您需要将类设置为其他内容并创建一个没有悬停的新类。

LinkButtonDelete.Enabled = false;
//then
LinkButtonDelete.Attributes["class"] = "linkButtonDeleteDisabled"; // give it a new class

或者

 LinkButtonDelete.CssClass = "linkButtonDeleteDisabled";

It sounds like it's acting exactly as you tell it to. It's showing the hover. If you don't want it to show the hover, when you are disabling the button, it sounds like you need to set the Class to something else and create a new class that doesn't have the hover.

LinkButtonDelete.Enabled = false;
//then
LinkButtonDelete.Attributes["class"] = "linkButtonDeleteDisabled"; // give it a new class

or

 LinkButtonDelete.CssClass = "linkButtonDeleteDisabled";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文