Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want the div to become '100% of the user's screen' (viewport), then the answers of @Itay and @Fujy are both correct.</p> <p>If you want the same position as the grandparent (960px), then first define a reset to the dimensions of the grandgrandparent (body). Then position the child the same way as the grandparent. Consider this code:</p> <pre><code>&lt;body&gt; &lt;div id="grandparent"&gt; &lt;div id="parent"&gt; &lt;div id="reset"&gt; &lt;div id="child"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Notice the <code>&lt;body&gt;</code> is the same width as the viewport and the grandparent will be positioned relative to this body/viewport. The child needs to be positioned in the same way as the grandparent. So first reset to the viewport: <code>#reset ( position:absolute; left:0; right:0; }</code>. Now it's easy to give the child the same declarations as the grandparent.</p> <p>The body/viewport/grandgrandparent is white, grandparent gray, parent blue, reset red and child green:</p> <p><img src="https://i.stack.imgur.com/vq31l.png" alt="Screenshot"></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;style&gt; * { margin: 0; padding: 0; } #grandparent { width: 960px; margin: 0 auto; background-color: lightgray; height: 100vh; } #parent { width: 320px; margin-left: 480px; height: 100px; border: 1px solid blue; background-color: rgba(0,0,255,.30); padding: 12px; } #reset { position: absolute; left: 0; right: 0; border: 1px solid red; background-color: rgba(255,0,0,.30); padding: 12px; } #child { width: 960px; /* same as grandparent */ margin: 0 auto; /* same as grandparent */ border: 1px solid green; background-color: rgba(0,255,0,.30); padding: 12px 0; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="grandparent"&gt; &lt;h1&gt;Grandparent&lt;/h1&gt; &lt;div id="parent"&gt; &lt;p&gt;The parent can be anywhere.&lt;/p&gt; &lt;div id="reset"&gt; &lt;div id="child"&gt; &lt;p&gt;Child has same position as grandparent.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Note 1: <code>#parent { ... }</code> and all <code>border</code>, <code>background</code> and <code>padding</code> are only to make the div's visible.</p> <p>Note 2: The y-position is still relative to the parent. For y-axis reset use <code>top:0; bottom:0;</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload