CSS3 Background Images

css3 multiple background images size

Background images / textures are being used and implemented in many ways, often adding the nicest of finishing touches to a website. It is now in CSS3 we can apply background image dimensions as well as use multiple background images.

The CSS3 background-size is written background-size: Apx Bpx;
- Apx = x-axis (width)
- Bpx = y-axis (height)

Background-Size

This panel is using 270 by 500 pixel image downsized to 100 by 200 pixels.

  1. CSS3 Background Image (Size)
  2. #my_CSS3_id {
  3. background:url(image_1.extention) bottom right no-repeat;
  4. -moz-background-size: 100px 200px;
  5. -o-background-size: 100px 200px;
  6. -webkit-background-size: 100px 200px;
  7. }

An example for those on alternative browsers, not seeing the background-image effect..

Multiple Background Images

Applying multiple background images in CSS3 is quite easy, using a comma with the standard background property.

E.g. background: url(image_1.extention) top right no-repeat, url(image_2.extention) bottom right no-repeat;

This panel uses three seperate images in its background.

  1. CSS3 Background Image (Multiple)
  2. #my_CSS3_id {
  3. background: url(image_1.extention) top left no-repeat,
    url(image_2.extention) bottom left no-repeat,
    url(image_3.extention) bottom right no-repeat;
  4. }

An example for those on alternative browsers, not seeing the background-image effect..

The Zen Elements CSS3 Series

Thank you for reading!
Alex | @ZenElements

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

5 Comments on “CSS3 Background Images”

  1. Dale Hay 15.01.2009 at 5:55 pm

    Hopefully this becomes available in FF3 soon… (and also the other browsers) as this would make a lot of things easier for me to do instead of having to have two divs behind a div to make the effect of two backgrounds.

  2. Zen Elements 15.01.2009 at 8:17 pm

    I agree that it would be a fantastically useful addition to the CSS arsenal.
    I shall continue to badger the browsers into supporting it – among the other CSS 3 bits ‘n’ pieces – if you will!

  3. Rudi 23.01.2009 at 7:24 am

    i can’t wait to see this work on every browser :D
    nice article

  4. noob 02.12.2009 at 6:17 pm

    I can’t wait for this to be implemented on all browsers…
    I was playing with this but I can’t get it to work.

    I have 3 images as background in the body tag – image1 top left repeat-y, image2 top center no-repeat, image3 top right repeat-y.

    Is there a way in CSS3 to make the width of image1 and image 3 auto and height 100% but leave image2 static width size of the jpg? If so, then this will save all the trouble!!

    Thanks!!

  5. Stephen Belanger 28.06.2010 at 10:52 pm

    Finally, a solution to the need for double divs to make rounded corners!

    …oh, wait… >.>

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)