How to style a HTML label for disabled input

后端 未结 5 1078
遇见更好的自我
遇见更好的自我 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 04:02

    You can also use floats and always put the label after the input Demo

    You will have to wrap it in a span (or any other element really).

    HTML :

    
        
        
    
    

    CSS :

    span {
        display: inline-block;
        overflow: hidden;
    }
    
    input {
        float: right;
    }
    
    label {
        float: left;
    }
    
    input:disabled {
        background:#ffffdffffd;
    }
    
    input + label {
        float: none;
    }
    
    input:disabled + label {
        color:#ccc;
    }
    

提交回复
热议问题