title: Is it possible for absolute div to have width: auto, and also ignore it's parent's width?
body: <p>I'm trying to make a <code>div</code> that stretches to fit its content, up to some maximum width, after which the content should wrap.</p>
  
  <p>Using an absolutely positioned <code>div</code> works fine -- unless its parent's width is limited. When its parent's width is limited, the absolutely positioned <code>div</code> acts as though its <code>max-width</code> is the <code>width</code> of its parent.</p>
  
  <p>I'd essentially like for the absolutely positioned <code>div</code> to "pretend" its parent has 100% width, and give me the nice "stretch-to-fit" behavior, while honoring the <code>max-width</code> I set on it.</p>
  
  <p>In the below example, I'd like the first <code>.abs</code> to work, even though it is a child of a "skinny" div.</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>.parent {
    position: relative;
    background: #EEE;
    width: 100px;
  }
  .abs {
    position: absolute;
    max-width: 200px;
    /* width:  auto, but ignore parent! */
  }
  
  .parent2 {
    margin-top: 150px;
    background: rgba(0,128,0,.1);
    width: 100px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;div class="parent"&gt;
      &lt;div&gt;
        Doesn't work.
      &lt;/div&gt;
      &lt;div class="abs"&gt;
        This wraps after 100px, because it's parent has 100px width.
      &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div class="parent2"&gt;
      &lt;div&gt;
        Does work.
      &lt;/div&gt;
      &lt;div class="abs"&gt;
        This wraps at 200px, because it's parent is as wide as the viewport, so it honors the max-width of 200px.
      &lt;/div&gt;
    &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://jsfiddle.net/nqws2p09/1/" rel="nofollow noreferrer">https://jsfiddle.net/nqws2p09/1/</a></p>