How to style a HTML label for disabled input

后端 未结 5 1117
遇见更好的自我
遇见更好的自我 2020-12-29 03:16

I would like the labels for my form elements to be greyed out if the input is disabled and am not able to get it to work for text inputs. I have tried the following:

<
5条回答
  •  无人及你
    2020-12-29 03:52

    This selector input:disabled+label{color:#ccc;} targets label elements that are placed after an input element that is disabled

    In this snippet the label is after a disabled input, so the label element is gray

    
    
    

    In this case, the label is before the input so the selector does not apply to it

    
    
    

    Possible solution would be to wrap your elements in an extra div and apply a class name to the div, something like this

    And then you can write your css like this

    .disabled label {
        color: #ccc;
    }
    

提交回复
热议问题