Is it possible to change a fieldset's background-color on input:focus?

前端 未结 5 577
刺人心
刺人心 2020-12-20 23:04

Is it possible to have the background-color of a form\'s fieldset change when the cursor is inside any of that fieldset\'s text fields?

I assumed this might work, b

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 23:34

    This is now possible with :focus-within

    The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. (This includes descendants in shadow trees.)

    MDN

    fieldset {
      background: green;
      margin: 1em;
    }
    
    fieldset:focus-within {
      background: red;
    }

提交回复
热议问题