Changing body background when hovering over a link

后端 未结 3 1843
情话喂你
情话喂你 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:38

    It's not very pretty, but you can use the :before pseudo-element on body

    link 1
    

    CSS:

    body {
        background: #fff;
    }
    
    a.change-bg:hover:before {
        content:'';
        position: absolute;
        display: block;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: -1;
        background-color: #000;
    }
    

    http://jsfiddle.net/bjsvhze8/13/

提交回复
热议问题