title: Have a different color before and after a div with CSS
body: <p>For a website I'm trying to get the element before a container to appear in a different color than the element after a container. I want to get the following result:</p>
  
  <p><a href="https://i.stack.imgur.com/C8yeF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/C8yeF.png" alt="Example of the result"></a></p>
  
  <p>I've tried this one: <a href="https://stackoverflow.com/questions/41807202/css-before-after-background-color">CSS :before :after background color</a>. Also a lot of other stuff but it all didn't work out. I ended up with the following code:</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>.section {
    width: 100%;
  }
  
  .section .container {
    background-color: #fff;
    width: 250px;
    margin: 0 auto;
    text-align: center;
  }
  
  .section .container::before {
    background-color: red;
    content: ' ';
  }
  
  .section .container::after {
    background-color: blue;
    content: ' ';
  }
  
  .section .container h1 {
    padding: 10px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="section"&gt;
    &lt;div class="container"&gt;
      &lt;h1&gt;Hello world.&lt;/h1&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The result is just white.</p>