ASP.Net checkbox missing CSS class

前端 未结 5 1584
走了就别回头了
走了就别回头了 2020-12-17 15:03

I have the following ASP.Net check box control added to a page:

Bu

相关标签:
5条回答
  • 2020-12-17 15:42

    I found a different answer to this, you can use the property

    MyCheckBox.InputAttributes["class"] = "myClass";
    

    to assign a class directly to an asp checkbox from the codebehind. Just noting this since I found this post through Google and the answer specified wouldn't work for me.

    0 讨论(0)
  • 2020-12-17 15:47

    This post is quite old, but I'll post my solution to help anyone coming from google (like me).

    You can use the child selector > in jQuery, because the wrapping span has the CssClass that you specified, and one input child. In your code:

    $('.myClass > input').addClass("myClass");
    
    0 讨论(0)
  • 2020-12-17 15:47

    You could wrap it in a span with a class.

    0 讨论(0)
  • 2020-12-17 15:56

    Ok, when you apply a CssClass to the ASP.Net check box control it applies the class to a span that wraps the check box. Because the css class isn't applied directly to the element it doesn't override the class that has been applied to all input elements.Therefore I used jQuery to select the element and apply the necessary style.

    $("input[type=checkbox]").addClass("myClass");
    
    0 讨论(0)
  • 2020-12-17 15:59

    You can alos just set the css class like

        <asp:CheckBox ID="cbValittu" runat="server" Checked='<%# Eval("Valittu")%>' Class="checBoks" />
    
    Css class can look something like:
    .checBoks input
    {
        width: 18px;
        height: 18px;
        vertical-align:middle;
    }
    
    0 讨论(0)
提交回复
热议问题