Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>CSS example for two non-scrolling background images</h1> <p>Some browsers (Safari) allow (CSS3) multiple background images, but since these aren't yet universal, here's my solution.</p> <p>For a start, you don't need a fixed position div. You can prevent the background image from scrolling by using:</p> <pre><code>background-attachment: fixed; </code></pre> <p>Use background-position to put the background top, bottom, center, right, left e.g.</p> <pre><code>background-position: top right; </code></pre> <p>And set background-repeat to the setting you want.</p> <h2>The CSS</h2> <p>The CSS below will give you two background images that don't scroll in the page background - set the width of #mydiv to whatever you want (or leave it unset for 100%) and its height to 2000px (just to test the scrolling), and use your image URLs instead of the example: </p> <pre><code>body { background-image: url(body_background.gif); background-attachment: fixed; } #mydiv { position: absolute; right: 0px; /* or whatever */ background-image: url(div_background.gif); background-attachment: fixed; } </code></pre> <h2>The HTML</h2> <p>If you need a complete example, change the background image URLs and use this (obvious) HTML/CSS example as a starting point:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;untitled&lt;/title&gt; &lt;style type="text/css"&gt; body { background-image: url(body_background.gif); background-attachment: fixed; } #mydiv { position: absolute; top: 0px; /* 0 is default for top so remove or make &gt; 0 */ right: 0px; /* or left, whatever you need */ width: 250px; /* or whatever you want */ height: 1500px; /* remove after testing! */ background-image: url(div_background.gif); background-attachment: fixed; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="mydiv"&gt; the div &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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