Changing body background when hovering over a link

后端 未结 3 1846
情话喂你
情话喂你 2020-12-11 14:12

I would like to set up my page so that when the user hovers over a link in a div, the color of the body background is changed, but only while hovering. This is the css

3条回答
  •  佛祖请我去吃肉
    2020-12-11 14:48

    What you want to do is actually not possible with CSS as you are asking if there is a parent selector BUT we can use some workarounds.

    Here is an idea where I use a pseudo element from the a that I make it to cover the whole body and it behaves as the background of the body:

    a {
      color: white;
      text-decoration: none;
    }
    
    a:before {
      content: "";
      position: fixed;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      background: #000;
      z-index: -1;
      pointer-events:none;
    }
    
    a:hover::before {
      background: red;
    }
    link

提交回复
热议问题