Friday, July 8, 2011

Multiple Backgrounds with CSS3

CSS3 allows web designers to specify multiple background images for box elements, using nothing more than a simple comma-separated list.

Browser support for multiple backgrounds is relatively widespread with Mozilla Firefox (3.6+), Safari/Chrome (1.0/1.3+), Opera (10.5+) and even Internet Explorer (9.0+) all implementing the feature.

Here’s a basic example:

This box has two background images, the first a balloon (aligned to the top and center) and the second a grass and sky background
(aligned to the top-left corner).


<div class="examplemultiplebackgrounds">
<p>This box has two background images, the first a balloon 
(aligned to the top and center) and the second a grass and sky background 
(aligned to the top-left corner).</p>
  </div>

<style type="text/css">  
div.examplemultiplebackgrounds
{   
 width: 446px;
 height: 395px;
 background-image: url(images/balloon-orange.png), url(images/landscape.jpg);
 background-position: center 50px, left top;
 background-repeat: no-repeat;

}
div.examplemultiplebackgrounds p
{
 font-size: 14px;
 color: #ffffff; 
 padding: 5px;
}
</style>

No comments:

Post a Comment