admin管理员组

文章数量:1401771

css code

body {
    background-color: rgb(224,224,224,0.6); 
  background: url(../img/backlogo.png),url(../img/backlogo2.png);

}

I want to give two background images one after the other alternately.I have shown the output in the . I want the two images repeated one next to other.

css code

body {
    background-color: rgb(224,224,224,0.6); 
  background: url(../img/backlogo.png),url(../img/backlogo2.png);

}

I want to give two background images one after the other alternately.I have shown the output in the . I want the two images repeated one next to other.

Share Improve this question edited Dec 9, 2015 at 6:19 Pranav C Balan 115k25 gold badges171 silver badges195 bronze badges asked Dec 9, 2015 at 5:49 Harsh DesaiHarsh Desai 751 silver badge8 bronze badges
Add a ment  | 

7 Answers 7

Reset to default 2

Try something like this

body {
  background-color: rgb(224, 224, 224, 0.6);
  background: url(https://upload.wikimedia/wikipedia/mons/c/c3/Acid2.png), url(http://easycarkeys./images/accept.png);
  background-repeat: no-repeat, no-repeat;
  background-position: right center, left center;
  height:250px;
}

Ref : Using CSS multiple backgrounds


UPDATE : To avoid overflow set background position based the width and height of other background image

body {
  background-color: rgb(224, 224, 224, 0.6);
  background: url(https://upload.wikimedia/wikipedia/mons/c/c3/Acid2.png), url(http://easycarkeys./images/accept.png);
  background-repeat: no-repeat, no-repeat;
  background-position:  200px  center,left center;
  height:250px;
}

Try Something like,

body {
  background-image: url(sheep.png), url(betweengrassandsky.png);
  background-position: center bottom, left top;
  background-repeat: no-repeat;
}

Multiple Background

CSS3 allows this sort of thing and it looks like this:

body {
    background-image: url(images/bgtop.png), url(images/bg.png);
    background-repeat: repeat-x, repeat;
}

The current versions of all the major browsers now support it, however if you need to support IE8 or below, then the best way you can work around it is to have extra divs:

<body>
    <div id="bgTopDiv">
        content here
    </div>
</body>

body{
    background-image: url(images/bg.png);
}
#bgTopDiv{
    background-image: url(images/bgTop.png);
    background-repeat: repeat-x;
}

Here is the working demo.

You gotta give background-position to stack the background image

body {  
    background:
      url(http://s3-media1.fl.yelpcdn./bphoto/y2kT6dH4XBt3hJoTsOeHKA/ls.jpg) no-repeat  top right,
      url(http://s3-media1.fl.yelpcdn./bphoto/lcBBwRuHvzHIVI6tors32A/ls.jpg) no-repeat top left;
  }
<body></body>

This works wonders for me:

body {
background: url("images/bgInit1C.gif") no-repeat scroll 0px 0% transparent url("images/bgInit1Repeat.gif") repeat-y scroll 0px 0px;
}

With this code, the two images overlap, but you can change their x y values for different positioning.

Here is an example making multiple background images using css, CSS3 Backgrounds

#example1 {
  background-image: url(img_flwr.gif), url(paper.gif);
  background-position: right bottom, left top;
  background-repeat: no-repeat, repeat;
}
#sample1 {
  background-image: url(image/sample1.gif), url(image/samplle2.gif);
  background-position: right bottom, left top;
  background-repeat: no-repeat, repeat;
}

本文标签: javascriptHow to give two alternate background imagesStack Overflow