Using :focus to style outer div?

后端 未结 10 751
礼貌的吻别
礼貌的吻别 2020-12-02 18:24

When I begin writing text in the textarea, I want the outer div, with a class box, to have it\'s border turned solid instead of dashed, but somehow the :focus doesn\'t apply

10条回答
  •  被撕碎了的回忆
    2020-12-02 18:28

    This can now be achieve through the css method :focus-within as examplified in this post: http://www.scottohara.me/blog/2017/05/14/focus-within.html

    /*
      A normal (though ugly) focus
      pseudo-class.  Any element that
      can receive focus within the
      .my-element parent will receive
      a yellow background.
    */
    .my-element *:focus {
      background: yellow !important;
      color: #000;
    }
    
    /*
      The :focus-within pseudo-class
      will NOT style the elements within
      the .my-element selector, like the
      normal :focus above, but will
      style the .my-element container
      when its focusable children
      receive focus.
    */
    .my-element:focus-within {
      outline: 3px solid #333;
    }

    A paragraph

    My Website

提交回复
热议问题