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 badges7 Answers
Reset to default 2Try 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
版权声明:本文标题:javascript - How to give two alternate background images? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744316837a2600306.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论