title: how to center align a sub div
body: <p>I need to center align a sub div within the parent div without using <code>text-align:center</code> / <code>align:center;</code></p>
  
  <p>Basically I tried the following example. I realise that in order for <code>margin:auto</code> to work, I need to specify a width (cannot use auto) into the sub div. But how can I do it if the sub div width varies from 0px to 500px? </p>
  
  <p>see the example:</p>
  
  <pre><code>&lt;div style="width:450px;height:500px;background:pink;"&gt;
      &lt;div style="width:100px;height:200px;background:black;color:#fff;margin:auto;"&gt;
          hello world
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>