如何应用 ASP.net 下拉列表的禁用样式

How to apply disabled style of ASP.net dropdownlist

假设我在 ASP.net 中有一个这样的下拉列表:

<asp:DropDownList ID="ddOwnershipDocumentType" class="msbdd" runat="server">
</asp:DropDownList>

这里是 msdbdd 的定义:

.msbdd {
    font-family: WMitraBold;
    font-weight: normal;
    color: #000;
    font-size: 12px;
    text-align: right !important;
    direction: rtl;
    width: 100%;
    border: 1px solid #aaa;
    outline: none;
    box-sizing: border-box;
    background-color: rgba(255,255,255,0.7);
}

我正在尝试在该下拉列表被禁用时对其应用样式。我尝试了 .msbdd select[disabled].msbdd select:disabled.msbdd select[readonly].msbdd select:read-only,但它们都不起作用(在 Chrome 中)。

如何在 CSS 中选择禁用的下拉列表?

试试这个:

<asp:DropDownList ID="ddOwnershipDocumentType" CssClass="msbdd" runat="server">
</asp:DropDownList>

请注意 CssClass 属性而不是 class 属性。

CSS:

select[disabled].msbdd {
    font-family: WMitraBold;
    font-weight: normal;
    color: #000;
    font-size: 12px;
    text-align: right !important;
    direction: rtl;
    width: 100%;
    border: 1px solid #aaa;
    outline: none;
    box-sizing: border-box;
    background-color: rgba(255,255,255,0.7);
}

如果你改变

<asp:DropDownList ID="ddOwnershipDocumentType" class="msbdd" runat="server">
</asp:DropDownList>

<asp:DropDownList ID="ddOwnershipDocumentType" CssClass="msbdd" runat="server">
</asp:DropDownList>

class 到 CssClass,您的代码应该类似于 this.

然后你可以select/用select.msbdd:disabled设置样式。

参见 fiddle 上的 Demo