Note that there are some explanatory texts on larger screens.

plurals
  1. PObody background extends into margins or is cut-off when scrolling
    primarykey
    data
    text
    <p>I have a layout where I need to use height: 100% on html and body (and any wrapper divs I resort to using) to achieve an effect similar to pages, so that the content on my first "page" is centred, scrolling down the content on the second "page" is centred etc.</p> <p>The html looks like this:</p> <pre><code>&lt;section class="page" id="p01"&gt; &lt;div class="spacer"&gt; &lt;/div&gt; &lt;div class="outer"&gt; &lt;div class="inner"&gt; Some content &lt;/div&gt; &lt;div class="inner"&gt; Some content &lt;/div&gt; &lt;/div&gt; &lt;/section&gt; &lt;section class="page" id="p02"&gt; &lt;div class="spacer"&gt; &lt;/div&gt; &lt;div class="outer"&gt; &lt;div class="inner"&gt; Some content &lt;/div&gt; &lt;div class="inner"&gt; Some content &lt;/div&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p>and the vertical centring etc. achieved with this styling:</p> <pre><code>body, .page {height: 100%; margin: 0 auto;} .spacer { float: left; height: 50%; margin-bottom: -150px; } .outer { height: 300px; width: 100%; background-color: #fca; clear: both; position: relative; display: block; white-space: nowrap; } .inner { width: 41%; margin: 0 6%; height: 300px; background-color: green; display: inline-block; vertical-align: middle; white-space: normal; } .inner:first-child { margin-right: 0; } </code></pre> <p>You can see it at work in this fiddle: </p> <p><a href="http://jsfiddle.net/terraling/3V5rV/" rel="nofollow">http://jsfiddle.net/terraling/3V5rV/</a></p> <p>The problem is the body background (here I'm just using color, but on my site it will be an image) leaks out into the body margins, i.e. the body content has a max-width and should be centred with white margins.</p> <p>I can fix that either by... setting html background-color to white, as per</p> <p><a href="http://jsfiddle.net/terraling/yM53t/" rel="nofollow">http://jsfiddle.net/terraling/yM53t/</a></p> <p>...but body background becomes cutoff when scrolling into the second page (that wasn't a problem in the first fiddle).</p> <p>Alternatively I could set the background image on a wrapper div and not on the body. That solves the problem of it leaking into the body margins, but it still has the same problem that it is cut off on scrolling.</p> <p>(see: <a href="http://jsfiddle.net/terraling/3V5rV/1/" rel="nofollow">http://jsfiddle.net/terraling/3V5rV/1/</a> )</p> <p>Any solution that involves removing the height: 100% declaration from any of html, body or wrapper collapses the layout (including replacing with max-height: 100%).</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.
    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