Anyway to have a label respond to :focus CSS

后端 未结 3 1254
一生所求
一生所求 2020-12-20 11:22

Is there any way to have a label respond to focus. I have some code where the textfield has a different style on focus. The label also however needs a slightly different sty

3条回答
  •  有刺的猬
    2020-12-20 12:08

    You can't actually give focus to a label. It's not a focusable form element. Besides, even if you could do that, then whatever previously had focus (that means your input) would lose it to the label anyway.

    You may have to restructure your HTML (and modify your CSS accordingly) so that you can select input:focus and then that input's corresponding label. For instance, if you moved your label after your input and used the following CSS selector for your label, you should be able to accomplish what you want.

    #header .search input:focus + label
    

提交回复
热议问题