How to change font-color for disabled input?

后端 未结 10 1026
逝去的感伤
逝去的感伤 2020-12-02 12:48

I need to change the style for a disabled input element in CSS.



        
相关标签:
10条回答
  • 2020-12-02 13:41

    It is the solution that I found for this problem:

    //If IE

    inputElement.writeAttribute("unselectable", "on");

    //Other browsers

    inputElement.writeAttribute("disabled", "disabled");

    By using this trick, you can add style sheet to your input element that works in IE and other browsers on your not-editable input box.

    0 讨论(0)
  • 2020-12-02 13:43

    The following gets you pretty close in IE8 and works in other browsers too.

    In your html:

    <input type="text" 
           readonly="readonly"    <!-- disallow editting -->
           onfocus="this.blur();" <!-- prevent focus -->
           tabindex="-1"          <!-- disallow tabbing -->
           class="disabledInput"  <!-- change the color with CSS -->
           />
    

    In your CSS:

    .disabledInput {
        color: black;
    }
    

    In IE8, there is a slight amount of border color change on hover. Some CSS for input.disabledInput:hover could probably take care of this.

    0 讨论(0)
  • 2020-12-02 13:43

    This works for making disabled select options act as headers. It doesnt remove the default text shadow of the :disabled option but it does remove the hover effect. In IE you wont get the font color but at least the text-shadow is gone. Here is the html and css:

    select option.disabled:disabled{color: #5C3333;background-color: #fff;font-weight: bold;}
    select option.disabled:hover{color:  #5C3333 !important;background-color: #fff;}
    select option:hover{color: #fde8c4;background-color: #5C3333;}
    <select>
         <option class="disabled" disabled>Header1</option>
         <option>Item1</option>
         <option>Item1</option>
         <option>Item1</option>
         <option class="disabled" disabled>Header2</option>
         <option>Item2</option>
         <option>Item2</option>
         <option>Item2</option>
         <option class="disabled" disabled>Header3</option>
         <option>Item3</option>
         <option>Item3</option>
         <option>Item3</option>
    </select>

    0 讨论(0)
  • 2020-12-02 13:47

    You could use the following style with opacity

    input[disabled="disabled"], select[disabled="disabled"], textarea[disabled="disabled"] {
        opacity: 0.85 !important;
    }
    

    or a specific CSS class

    .ui-state-disabled{
        opacity: 0.85 !important;
    }
    
    0 讨论(0)
提交回复
热议问题