On input focus change color of label. How?

前端 未结 5 1726
终归单人心
终归单人心 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:08

    One solution would be to use the :focus-within selector.

    So, you'd do something like the below. Assuming that you always have an input of some description inside of a control-group, it will style the label whenever the input is focused on.

    control-group {
        &:focus-within {
            control-label {
                color: red; 
            }
        }
    }
    

    More information can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within

提交回复
热议问题