CSS two background images using a sprite

半腔热情 提交于 2019-12-08 20:46:29
Stephen Parish

You could, instead, create two divs within the body:
Not as simple as CSS only, but it allows you to use your sprites.

The HTML:

<body>
  <div id="bgOne"></div>
  <div id="bgTwo"></div>
</body>

The CSS:

body {
  min-width: 1150px;
}

#bgOne, #bgTwo {
  position: fixed;
  height: 400px;
  width: 600px;
}

#bgOne {
  background: url('images/bktopright.png') no-repeat right top;
  right: 0;
  top: 0;
}

#bgTwo {
  background: url('images/bkbottomleft.png') no-repeat left bottom;
  left: 0;
  bottom: 0;
}

Here's the answer for you with a working example.

http://jsfiddle.net/ctLZY/

 <div class="bg" id="bg1"></div>
 <div class="bg" id="bg2"></div>​

CSS

.bg{
    background-image: url("someimage.png");
    background-repeat: no-repeat;
    position:fixed;
    width:100px;
    height:100px;
}
#bg1{
    background-position: -50px 0px;
    right:0px; top:0px;
}
#bg2{
    background-position: 50px 0px;
    left:0px; bottom:0px;
}​

You can refer the below links for more info.
Css3.info
Css-Tricks
This is the method that I came across. There might be better methods to handle this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!