Multiple backgrounds
Layering backgrounds inside a single box.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Multiple backgrounds</title>
<style>
body {
font: 14px/1.5 courier, monospace;
background: white;
color: black;
margin: 20px;
}
pre, #htmldog {
background-color: #c72;
height: 200px;
margin: 20px 0;
overflow: auto;
}
pre code {
background: white;
padding: 2px 10px 4px 0;
}
#p0, #htmldog {
background-image: url("http://www.htmldog.com/examples/images/bg.gif");
}
#p1 {
background-image: url("http://www.htmldog.com/examples/images/circle.png"), url("http://www.htmldog.com/examples/images/bg.gif");
}
#p2 {
background-image: url("http://www.htmldog.com/examples/images/circle.png"), url("http://www.htmldog.com/examples/images/bg.gif");
background-repeat: no-repeat, repeat;
}
#p3 {
background-image: url("http://www.htmldog.com/examples/images/circle.png"), url("http://www.htmldog.com/examples/images/bg.gif");
background-repeat: no-repeat, repeat;
background-position: center;
}
#p4 {
background: url("http://www.htmldog.com/examples/images/circle.png") center no-repeat, url("http://www.htmldog.com/examples/images/bg.gif");
}
#htmldog a {
display: block;
height: 200px;
background: url("http://www.htmldog.com/examples/images/cornerbg.gif") top -15px left -15px, url("http://www.htmldog.com/examples/images/cornerbg.gif") top -15px right -15px, url("http://www.htmldog.com/examples/images/cornerbg.gif") bottom -15px right -15px, url("http://www.htmldog.com/examples/images/cornerbg.gif") bottom -15px left -15px, url("http://www.htmldog.com//badge1.gif") center;
background-repeat: no-repeat;
text-indent: -999em;
transition: background-position .5s steps(2);
}
#htmldog a:hover {
background-position: top -25px left -25px, top -25px right -25px, bottom -25px right -25px, bottom -25px left -25px, center;
}
</style>
</head>
<body>
<h1><a href="http://www.htmldog.com/guides/css/advanced/backgrounds/">Multiple backgrounds</a></h1>
<p>Using the <a href="http://www.htmldog.com/references/css/properties/background-image/"><code>background-image</code></a> and <a href="http://www.htmldog.com/references/css/properties/background/"><code>background</code></a> CSS properties.</p>
<pre id="p0"><code>background-image: url("bg.gif");</code></pre>
<pre id="p1"><code>background-image: url("circle.png"), url("bg.gif");</code></pre>
<pre id="p2"><code>background-image: url("circle.png"), url("bg.gif");</code>
<code>background-repeat: no-repeat, repeat;</code></pre>
<pre id="p3"><code>background-image: url("circle.png"), url("bg.gif");</code>
<code>background-repeat: no-repeat, repeat;</code>
<code>background-position: center;</code></pre>
<pre id="p4"><code>background: url("circle.png") center no-repeat, url("bg.gif");</code></pre>
<!-- Link back to HTML Dog: -->
<p id="htmldog"><a href="http://www.htmldog.com/examples/"><img src="http://www.htmldog.com/badge1.gif" alt="HTML Dog"></a></p>
</body>
</html>