Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the reason why <code>#div2</code> extends below <code>#div1</code> is because in addition to being 100% the height of its parent, <code>#div2</code> is also pushed down by the four lines of text above it - so it extends exactly that distance outside of <code>#div1</code>. </p> <p>How to solve this, then? Well...I can offer a CSS solution, but it's not very flexible (a solution that employs JavaScript would definitely be more scalable, and less work to maintain). I modified your HTML structure slightly, so now it looks like:</p> <pre><code>&lt;div id="div1"&gt;Test &lt;br/&gt;Test &lt;br/&gt;Test &lt;br/&gt;Test &lt;div id="div3"&gt; &lt;div id="div2"&gt;Test&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>To clarify my changes, I added the <code>#div3</code> element around <code>#div2</code>. Now, for my CSS, I just added this definition for <code>#div3</code>, and modified the <code>body</code> CSS to:</p> <pre><code>body { margin: 0; line-height:1.3em; } #div3 { position:absolute; top:5.2em; bottom:0; left:0; width:100%; } </code></pre> <p>This approach requires that you know how far from the top of <code>#div1</code> you want <code>#div3</code> (and its child <code>#div2</code>) to start, which by extension requires you to know exactly how tall those four lines of text are. Since browsers often render text with slightly different line heights, I specified one for the <code>&lt;body&gt;</code>. After that, it is a fairly simple matter of multiplying that line height by the number of lines of text (four in this case), and setting that as the <code>top</code> attribute.</p> <p>Here's a <a href="http://jsfiddle.net/JZnba/" rel="nofollow">JSFiddle</a> to demonstrate what this achieves. I hope this answer was clear, and is what you're looking for! If not, let me know and I'll try to help further. Good luck!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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