css怎么做才能只显示图片的一部分

html-css014

css怎么做才能只显示图片的一部分,第1张

CSS Sprite

需要知道大图的网地,小图标在图上的位置偏移(写进css里的background-position要加负号),和大小。

<style>

.icon {

  background:url(background.png)

  background-repeat:no-repeat

  background-position:-25px -374px

  height:16px

  width:24px

}

</style>

<div class=".icon"></div>

background:url(pic.jpg) no-repeat left top

后面两个参数就是移动图片位置的,第一个是水平位置,如left或者right或者center,第2个是垂直位置,如top或者bottom或者center,也可以是数字,如

background:url(pic.jpg) no-repeat -10px -20px

具体看你要截取的位置