Using :focus to style outer div?

后端 未结 10 745
礼貌的吻别
礼貌的吻别 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:55

    DIV elements can get focus if set the tabindex attribute. Here is the working example.

    #focus-example > .extra {
      display: none;
    }
    #focus-example:focus > .extra {
      display: block;
    }
    Focus me!
    Hooray!

    For more information about focus and blur, you can check out this article.

    Update: And here is another example using focus to create a menu.

    #toggleMenu:focus {
      outline: none;
    }
    button:focus + .menu {
      display: block;
    }
    .menu {
      display: none;
    }
    .menu:focus {
      display: none;
    }

提交回复
热议问题