Change Style/Look of Asp:CheckBox using CSS

前端 未结 10 964
醉梦人生
醉梦人生 2020-12-10 13:55

I want to change the standard \"3D\" look of the standard asp.net checkbox to say solid 1px. If I try to apply the styling to the Border for example it does just that - draw

相关标签:
10条回答
  • 2020-12-10 14:34

    paste this code in your css and it will let you customize your checkbox style. however, it's not the best solution, it's pretty much displaying your style on top of the existing checkbox/radiobutton.

       input[type='checkbox']:after 
    {
    
            width: 9px;
            height: 9px;
            border-radius: 9px;
            top: -2px;
            left: -1px;
            position: relative;
            background-color: #3B8054;
            content: '';
            display: inline-block;
            visibility: visible;
            border: 3px solid #3B8054;
            transition: 0.5s ease;
            cursor: pointer;
    
    }
    
    input[type='checkbox']:checked:after 
        {
            background-color: #9DFF00;
        }
    
    0 讨论(0)
  • 2020-12-10 14:34

    Keep in mind that the asp:CheckBox control actually outputs more than just a single checkbox input.

    For example, my code outputs

    <span class="CheckBoxStyle">
        <input id="ctl00_cphContent_cbCheckBox" 
               name="ctl00$cphContent$cbCheckBox"
               type="checkbox">
    </span>
    

    where CheckBoxStyle is the value of the CssClass attribute applied to the control and cbCheckBox is the ID of the control.

    To style the input, you need to write CSS to target

    span.CheckBox input {
      /* Styles here */
    }
    
    0 讨论(0)
  • 2020-12-10 14:34

    They're dependent on the browser really.

    Maybe you could do something similar to the answer in this question about changing the file browse button.

    0 讨论(0)
  • 2020-12-10 14:37

    Rather than use some non-standard control, what you should be doing is using un-obtrusive javascript to do it after the fact. See http://code.google.com/p/jquery-checkbox/ for an example.

    Using the standard ASP checkbox simplifies writing the code. You don't have to write your own user control, and all your existing code/pages don't have to be updated.

    More importantly, it is a standard HTML control that all browsers can recognize. It is accessible to all users, and work if they don't have javascript. For example, screen readers for the blind will be able to understand it as a checkbox control, and not just an image with a link.

    0 讨论(0)
提交回复
热议问题