Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As other's have said, in order to change the <code>body</code> when an element is clicked, you'd need to have a parent selector. Since CSS has no parent selector capability, you will have to use a little javascript</p> <pre><code>// Set onclick function for the element you want document.getElementById('changeBG').onmouseover = function() { document.body.style.animation = "myfirst 0.01s 500"; //Give the body the anim // The above could also be done by adding a class with the animation // properties on click }; </code></pre> <p><a href="http://jsfiddle.net/g9Ss6/1/" rel="nofollow"><strong>Demo here</strong></a></p> <p>However, if you only want the background to flash when the link is hovered and to stop otherwise, you could do it in pure CSS using another HTML element (a kind of fake <code>body</code>). It requires that the fake-body element follow the link in the document flow like so</p> <pre><code>&lt;a id='changeBG' href='#'&gt;Change background&lt;/a&gt; &lt;div id='cover'&gt;&lt;/div&gt; </code></pre> <p>and the CSS for that fake-body element</p> <pre><code>#cover { position:absolute; /* Don't affect other elements */ top:0; left:0; /* Fill up the entire viewport */ width:100%; height:100%; z-index:-1; /* Be placed behind all other elements */ } </code></pre> <p>You would then use a sibling selector (I use <code>+</code> which is the directly following sibling) and <code>:hover</code> to give the animation to the fake-body</p> <pre><code>#changeBG:hover + #cover { -webkit-animation: myfirst 0.01s 500; animation: myfirst 0.01s 500; } </code></pre> <p><a href="http://jsfiddle.net/g9Ss6/4/" rel="nofollow"><strong>Demo of that approach</strong></a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload