On input focus change color of label. How?

前端 未结 5 1727
终归单人心
终归单人心 2020-12-20 14:19

On input focus I want to change the color of the label element. How can I achieve this in less?

.control-label{
      color: @gray-light;
}
.co         


        
5条回答
  •  伪装坚强ぢ
    2020-12-20 15:03

    One solution would be to move the label below the input in the DOM but position them absolutely (to the parent) so the label looks to be above the input field:

    In CSS move the label to the top, the input to the bottom:

    label {
      position: absolute
      top: 0
    }
    
    input {
      position: absolute
      bottom: 0
    }
    

    And use the :focus state to change the style of the label:

    input:focus + label {
        color: red
    }
    

    See example:

    http://codepen.io/robcampo/pen/zGKLgg

    On focus, the label turns red. No JS required.

提交回复
热议问题