Stylize element at various levels up

3

I would like to know how I can change the background of div # whatever by clicking on a li, as in the example below (using css only)

<div class="whatever"></div>
 <section class="content">
        <article class="personagens">
            <h2>Lista de Pokémons</h2>
            <h2>Lista de Digimons</h2>
            <ul>
                <li>Bulbasaur</li>
                <li>Ivysaur</li>
            </ul>
    
asked by anonymous 26.10.2016 / 14:32

2 answers

3

If you want to do purely with css stay like this

#a:hover + #b {
    background: #ccc;
}
<div id="a">Div A</div>
<div id="b">Div B</div>

This is just an ex but you adapt to your li

    
26.10.2016 / 14:51
3

To do this only with HTML / CSS it is necessary to use a hack with a checkbox.

If you link to the adaptation of this code :

#btnControl {
  display: none;
}
#btnControl:checked + .whatever {
  background: red;
}
.whatever {
  width: 50px;
  height: 50px;
  background: gray;
}
<input type="checkbox" id="btnControl" />
<div class="whatever"></div>

<section class="content">
  <article class="personagens">
    <h2>Lista de Pokémons</h2>
    <h2>Lista de Digimons</h2>
    <ul>
      <li>
        <label class="btn" for="btnControl">Bulbasaur</label>
      </li>
      <li>
        <label class="btn" for="btnControl">Ivysaur</label>
      </li>
    </ul>
  </article>
</section>

Font

    
26.10.2016 / 14:46