图标截取——背景偏移量技术
2018-02-23 23:20
99 查看
图标截取——背景偏移量技术
美工将若干个图标合在一起做成一张图片,怎么取出里面的每一个小图标来用呢?
比如icon.gif包含一些图标。
1、效果图
2、实现代码
通过设置width和height属性确定要截取图片的大小,background属性值得最后两个参数用于定位与大图片的位置,第一个参数是设置图片横向移动,负数表明往左移动,正数表明往右移;第二个参数是设置图片纵向移动,正数表明往下移动,负数表明往上移动。
美工将若干个图标合在一起做成一张图片,怎么取出里面的每一个小图标来用呢?
比如icon.gif包含一些图标。
1、效果图
2、实现代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>演示从大图中截取小图标</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"> <link href="bootstrap/css/bootstrap-theme.css" rel="stylesheet" type="text/css"> <script src="scripts/jquery-3.1.1.min.js"></script> <script src="bootstrap/js/bootstrap.js"></script> <style type="text/css"> .menu { width: 100%; height: 50px; float: left; } .menu li { list-style: none; float: left; } .pic1 { width: 28px; height: 26px; margin-top: -5px; background: url(images/icon.gif) no-repeat 0px 2px; } .pic2 { width: 28px; height: 26px; margin-top: -5px; background: url(images/icon.gif) no-repeat -28px 2px; } .pic3 { width: 28px; height: 26px; margin-top: -5px; background: url(images/icon.gif) no-repeat -84px 2px; } .pic4 { width: 28px; height: 26px; margin-top: -5px; background: url(images/icon.gif) no-repeat -112px 2px; } .btn { padding: 0px 5px; text-align: center; width: 50px; height: 26px; background: url(images/icon.gif) no-repeat 0px -28px; } </style> </head> <body> <div class="container"> <div class="row"> <div class="well col-md-6"> <div class="menu"> <ul> <li class="pic1"></li> <li><a href="#">购物车</a></li> <li class="pic2"></li> <li><a href="#">帮助中心</a></li> <li class="pic3"></li> <li><a href="#">加入收藏</a></li> <li class="pic4"></li> <li><a href="#">设为首页</a>;</li> <li class="btn"><a href="#">登录</a></li> <li class="btn"><a href="#">注册</a></li> </ul> </div> </div> </div> </div> </body> </html>解释说明:
通过设置width和height属性确定要截取图片的大小,background属性值得最后两个参数用于定位与大图片的位置,第一个参数是设置图片横向移动,负数表明往左移动,正数表明往右移;第二个参数是设置图片纵向移动,正数表明往下移动,负数表明往上移动。
相关文章推荐
- CSS中背景图片区域截取技术
- 【技术】photoshop切背景透明小图标
- Demo7:背景截取图标显示
- 有关css图片背景定位技术
- Android基础小技术点:Android ListView设置背景图片及分割线、周边距
- SQL里有取整函数,四舍五入函数,和截取函数 - eminem - JavaEye技术网站
- 安卓简单技术-设置背景透明
- PS把图标背景变为透明背景
- 标题滑动隐藏,滑动中背景图标变化,仿淘宝商祥
- [翻译的]蓝光技术的背景
- 怎么去掉桌面图标的背景
- IPv4向IPv6过渡的背景、技术、形式
- 导航栏图标背景颜色随点击发生变化
- Google Map开发系列(二)——使用谷歌地图API应该有所了解的一些技术外背景
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
- Win10自定义开始菜单磁贴背景颜色及图标
- Kooboo CMS技术文档之一:Kooboo CMS技术背景
- Android基础小技术点:Android ListView设置背景图片及分割线、周边距
- 自定义UISearchBar 适配IOS6和IOS7 修改放大镜图标 修改光标颜色 修改边框颜色 placeholder颜色 设置文本框背景
- 自定义UISearchBar背景、边框、左侧图标、删除图标、取消按钮