title: How to correctly align these elements with flexbox?
body: <p>Sorry for the really vague question title but I have no idea how to best describe it...</p>
  
  <p>Take the following code example:</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>.wrapper {
    border: 2px solid green;
  }
  
  .container { 
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    
    border: 2px solid red;
    margin: 5px;
    height: 64px;
  }
  
  .item {
    display: flex;
  
    border: 2px solid #0000ff;
    padding: 3px;
  }
  
  .left {
    justify-content: flex-end;
  }
  
  .right {
    justify-content: flex-start;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper" style="width: 100%"&gt;
    &lt;div class="container"&gt;
      &lt;div class="item left"&gt;FIXED&lt;/div&gt;
      &lt;div class="item right"&gt;abc&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;div class="item"&gt;FIXED&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;div class="item left"&gt;FIXED&lt;/div&gt;
      &lt;div class="item right"&gt;abcdefgh&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="wrapper" style="width: 50%"&gt;
    &lt;div class="container"&gt;
      &lt;div class="item left"&gt;FIXED&lt;/div&gt;
      &lt;div class="item right"&gt;abc&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;div class="item"&gt;FIXED&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container"&gt;
      &lt;div class="item left"&gt;FIXED&lt;/div&gt;
      &lt;div class="item right"&gt;abcdefgh&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Observations:</strong></p>
  
  <ul>
  <li><code>FIXED</code> represents an element of fixed size, <strong>always same width/height</strong>.</li>
  <li>The right side element can vary on size (mostly width).</li>
  <li>The right side element is <strong>always</strong> aligned to the left.</li>
  <li>The left side element is <strong>always</strong> aligned to the left.</li>
  </ul>
  
  <p><strong>What I'm trying to achieve:</strong></p>
  
  <ul>
  <li>The <code>FIXED</code> element should always be <em>centered</em> on the red row.</li>
  <li>THE <code>FIXED</code> element on the first/third rows needs to be aligned to the right side of the <code>FIXED</code> element on the second row.</li>
  </ul>
  
  <p><strong>Here's an image to better demonstrate what I'm looking for:</strong>
  <a href="https://i.stack.imgur.com/AHiiH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AHiiH.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT:</strong> My final solution based on the @vals answer. I had to change this a bit because I'm using CSS Modules with selector composition in a React app and I need a single class per element.</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>.container {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    
    /* UNREQUIRED (FOR DEMONSTRATION ONLY) */
    border: 2px solid red;
    padding: 5px;
  }
  
  .container::before {
    content: "";
    flex: 1 0 14px; /* UNREQUIRED (FOR DEMONSTRATION ONLY) (14px -&gt; 0) */
  }
  
  .container-single {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    
    /* UNREQUIRED (FOR DEMONSTRATION ONLY) */
    border: 2px solid red;
    padding: 5px;
  }
  
  .item {
    display: flex;
    flex: 0 0 auto;
    
    /* UNREQUIRED (FOR DEMONSTRATION ONLY) */
    border: 2px solid #0000ff;
    padding: 5px;
  }
  
  .item-right {
    display: flex;
    flex: 1 0 0;
    
    /* UNREQUIRED (FOR DEMONSTRATION ONLY) */
    border: 2px solid #0000ff;
    padding: 5px;
  }
  
  .item-left {
    display: flex;
    flex: 0 0 auto;
    margin-left: auto;
    
    /* UNREQUIRED (FOR DEMONSTRATION ONLY) */
    border: 2px solid #0000ff;
    padding: 5px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;div class="item-left"&gt;FIXED&lt;/div&gt;
    &lt;div class="item-right"&gt;abc&lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="container-single"&gt;
    &lt;div class="item"&gt;FIXED&lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="container"&gt;
    &lt;div class="item-left"&gt;FIXED&lt;/div&gt;
    &lt;div class="item-right"&gt;abcdefgh&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>For anyone interested, the CSS selector composition goes like this:</strong></p>
  
  <pre><code>.container {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
  }
  
  .container::before {
      flex: 1 0 0;
      content: "";
  }
  
  .container-single {
      composes: container;
  }
  
  .item {
      display: flex;
      flex: 0 0 auto;
  }
  
  .item-right {
      flex: 1 0 0;
  
      composes: item;
  }
  
  .item-left {
      margin-left: auto;
  
      composes: item;
  }
  </code></pre>