码迷,mamicode.com
首页 > Web开发 > 详细

CSS雪碧图的实现方法(即背景定位)

时间:2017-03-15 00:35:09      阅读:624      评论:0      收藏:0      [点我收藏+]

标签:ima   表示   技术分享   大小   img   方法   分享   log   http   

技术分享

 

如图:想往当前的容器内放一个背景图片上的某个小图片,当前容器暂用div表示

<div class="sprite"></div>

//样式

<style>

//首先设定容器的宽高,即要放置的小图片的大小,否则背景图片就会超出显示了 如图片背景图片大小为80*20,图片名称sprite01.png ,小图片的坐标位置为(67,97)所以小图的定位相对原点来说是(-67,-97),如此即可。

.sprite{ width:80px; height:20px; background:url(sprite01.png) no-repeat  -67px -97px;}

</style>

当然一定要记得no-repeat .如果没有加no-repeat图片会一直平铺吧背景大小铺满哟。

 

CSS雪碧图的实现方法(即背景定位)

标签:ima   表示   技术分享   大小   img   方法   分享   log   http   

原文地址:http://www.cnblogs.com/chenkewen2007/p/6551326.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!