Fixed Background Code

The quickest HTML code for applying a fixed background (and other background effects) is the background property.

Example Code


<!-- Codes by HTMLmagics -->
<div style="background:#fff url(http://htmlmagics.blogspot.com/images/backgrounds/background-image-2.gif) repeat fixed;
        overflow:scroll;
        width:200px;
        height:100px;">
<p>This example sets the fixed background image with one property - the 'background' property. This keeps the code shorter and easier to read. Here, we also use 'overflow:scroll' to ensure that the 'div' scrolls when the contents don't fit into it.</p>
</div>
<p><a  style="font-size:11px;color:#999;" href="http://htmlmagics.blogspot.com/backgrounds/fixed-background.cfm">Fixed Background</a></p>

Result




This example sets the fixed background image with one property - the 'background' property. This keeps the code shorter and easier to read. Here, we also use 'overflow:scroll' to ensure that the 'div' scrolls when the contents don't fit into it.