While the Mike Ross demo solves your problem, it does not explain how and why it works. It can also be greatly simplified.
Basically you want to use a notation ::before
for your element. This creates a pseudo-element, which is the first child of the related element for which you can apply an additional style. Then you can use the selector ::before
to fill the screen with a specific background color. For example:
<a class="special">Test</a>
.special:hover:before{
content: '';
position: fixed;
display: block;
top: 0; bottom: 0; left: 0; right: 0;
z-index: -1;
background-color: #ff0000;
}
You do not need nth-of-type
there or anything else. See my violin here . All you have to do is make sure that the before element is up to full screen, in z reverse order and has a specific color.
source
share