CSS: Change parent on focus of child

前端 未结 4 857
日久生厌
日久生厌 2020-12-13 01:43

Let\'s say you have something like:

<
4条回答
  •  Happy的楠姐
    2020-12-13 01:57

    There is no chance how to do that with CSS. CSS can style only siblings, children, etc. not parents.

    You can use simply JS like this:

    
    

    http://jsfiddle.net/C4bZ6/

    This code takes all direct children of .parent and if you focus one of them, class focused is added to parent. On blur, this class is removed.

提交回复
热议问题