title: CSS Transition between children
body: <p>Quick question. Does transition work if I hover over a child to target another child, or one separate div with another separate div?</p>
  <p>I can only get transition to work if I put the children in a container and hover over the parent. What are the rules to this?</p>
  <p>Example 1 (Doesn't work):</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body {
    display: flex;
    justify-content: center;
  }
  
  .underline {
    width: 0px;
    height: 2px;
    background-color: black;
    transition: 0.4s;
  }
  
  h2:hover .underline {
    width: 165px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
  
      &lt;h2&gt;Hover Over Me&lt;/h2&gt;
      &lt;div class="underline"&gt;&lt;/div&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Example 2 (Doesn't work)</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body {
    display: flex;
    justify-content: center;
  }
  
  .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 180px;
    height: 50px;
  }
  
  .underline {
    width: 0px;
    height: 2px;
    background-color: black;
    transition: 0.4s;
  }
  
  h2:hover .underline {
    width: 165px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
  
    &lt;div class="container"&gt;
      &lt;h2&gt;Hover Over Me&lt;/h2&gt;
      &lt;div class="underline"&gt;&lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Example 3 (Works)</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body {
    display: flex;
    justify-content: center;
  }
  
  .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 180px;
    height: 50px;
  }
  
  .underline {
    width: 0px;
    height: 2px;
    background-color: black;
    transition: 0.4s;
  }
  
  .container:hover .underline {
    width: 165px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
  
    &lt;div class="container"&gt;
      &lt;h2&gt;Hover Over Me&lt;/h2&gt;
      &lt;div class="underline"&gt;&lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>