Css Sprites – How They Work And Why Theyre Great-sichen

By , July 24, 2018 8:59 am

While it’s far from being a new technique, the use of CSS sprites is one of my favorites, for several reasons. A sprite is simply a group of images that have been .bined into a single file. Sprites allow you to reuse your image over and over, and hide or display different sections using a little bit of CSS. Creating A CSS Sprite The first step is going to be creating the image, so you’ll need to open up your favorite image editor. Before you create the sprite, you should have your individual images handy. Once they’re all organized and ready, you can get started. Firstly, decide how you wish to lay out your sprite. A lost of sprites are arranged in just one column, but it is possible to go horizontal, or create a grid with rows and columns. This decision is partly going to depend upon whether your images are all the exact same size, but also on your own personal preferences. Once you’ve decided how to line up the pictures, you’ll need to establish the total size of your sprite. Add all of the image dimensions together, based on how you plan to arrange them. If your images don’t already have a background color built in, leave a pixel of white space between each – add that to your total.. If you’re lining up 10 images which are 25px by 25 pixels, and you would like sprite with 2 rows of 5 images, your total dimensions would be 129 pixels by 51 pixels (thats 25×5, plus 4 single pixel gaps, and 25×2 plus 1 single pixel gap). I usually like to place my images in the order that they’re going to be used on the page, just for organizational purposes. Now the 2nd image. Build a row or column as you see fit by lining the second image up alongside the 1st, and repeat this process with the rest of your images. This will leave you with a sprite: all of your images, side by side with no touching or overlapping each other. Now you just save your file and you’re ready to move on to the code. CSS Sprite Code: Making It All Work Now we’ve .e to the REALLY fun part: the code that hides/displays the appropriate section of the image. The first piece of code will define all the .mon characteristics your different elements share: size, display, outline, whatever they all have in .mon – plus the background image (your sprite) You’re including that in this first batch of .mon CSS because you’ll use the same image for each element – all you’re really changing is the alignment. It’s important to remember to label this code as a container ID or class – that way you don’t affect other elements on the page. It’s also vital that you assign a unique ID to each element within the container. That is what makes the whole process work. Now let’s set up each elements background position. For these styles, we are going to list two elements, separated by a single space. First, the container, followed by the specific element that you are applying the background property to. This is called "nesting."Doing this ensures that this element, and only this element are targeted by this style – protecting you in the event that you inadvertently reuse your unique ID somewhere outside the container you’ve set up. Now that you’ve selected the right item to apply the first section of the sprite to, you just need to add the "background-position" parameter. Assuming that the first image on the sprite is the one you’re using for your first element, the default value of "top left" will work just fine. "Top left" tells visiting browsers to align the top edges of both the background image and the element, as well as aligning the left hand images of both as well. In addition to "top" and "left" values of "right," "center," and "bottom" can be used as well. You also have the option of using variables to designate how many pixels the image should shift vertically or horizontally. Now, it’s important to remember that the edge values (top, left, right, bottom) can be listed in whatever order .es naturally, but for values like "center" or a number that could apply to either axis, you must always list the x-axis (horizontal) first – that’s just how the browser is going to interpret the code. The second line is where it gets fun. In our earlier example, we used 25 pixel images. To display the second image, our horizontal value would be 25px. This will slide the entire background image 25 pixels to the left of the edge of the element. As a result, the first 25 pixels of your background are now hidden, allowing the second 25 pixels to display, giving the appearance of a .pletely different image. If I lost you at all with that last step, just imagine a graph. The starting point, or 0,0, is at the top left corner of your image. You simply need to select new coordinates from there to decide where the top left corner of the SPRITE should be. Positive numbers move your sprite up and right, negative down and left. The second image would need a horizontal value of -50, to slide the sprite over one more image. The same principle applies to displaying different rows of your sprite: just change the second value and leave the first one alone. If you have a grid, you can change both.. We did it!Our CSS is now automatically loading our background image, and placing it so that the right section is visible for each of the three buttons! You can add as many rules as you need to for as many images as you want. And that’s really all there is to it! 1. Create your images 2. .bine your images 3. Define the .mon characteristics of the elements in a single style 4. Give each element a unique ID 5. Write some targeted rules for each elements unique ID 6. Take a nap Sprites like these can be used for almost anything, not just buttons. You could use them for graphic bullets if you write a lot of lists, or even create fancy images of numbers for numbered lists. You can use sprites to display fancy titles on things like sidebar widgets: the sky’s the limit. Virtually anywhere you use an image, you can incorporate a sprite to speed things up. 相关的主题文章:

Comments are closed

haole10.com,midd-885,www.9999mp.com,www.ggg258.com,www.yyy13.com,haha视频 www.1hhh.com,www.tubecao.com,www.sdcp.cn,haha视频,火牛视频 k17.cc,友链交换,haha视频,火牛视频 火牛视频,haha视频,www.nmec.org.cn 519697,友链交换,火牛视频,haha视频 www.yiyi.cc,www.cqpx.cc,www.cnool.net,www.xici.net,www.yofoto.cn,haha视频 zghd,ppp13.com,www.ddd13.com,www.cm68.com,ca1290,周同宇,haha视频,火牛视频 www.jhyc.cn,www.kisstudou.com,友链交换,haha视频,火牛视频 kkxxse.com,www.jhyc.cn,ekdv-273,sayu-02,haha视频,火牛视频 pppd-175,www.zhibo8.cc,haha视频 haha视频 www.40sqw.com,haha视频 haha视频,火牛视频 www.h4610.com,巴特尔道尔吉,石悦军,许皓博,友情链接交换,haha视频,火牛视频 www.xinkebiao.com.cn,www.souhu.com,佃庄吧,宋世长,imjpmig,万万没想到之鹿晗篇,三胞胎替母寻夫,友链交换,haha视频,火牛视频 xingbayounichunnuanhuakai,haha视频,友链交换 www.ddd13.com,www.cm68.com,www.kfc.com.cn,3u8813,ca1834,9c8947,haha视频,火牛视频 4987tv影视,友情链接是什么意思,友情链接的作用 haha视频,kkxxse.com,www.tubecao.com 友链交换,火牛视频,haha视频 翁其钊,haha视频,火牛视频 minmi,yezimei,火牛视频,haha视频 火牛视频,haha视频,友链交换 mcncc,www.33bbb.com,haha视频 www.yofoto.cn,www.cqpx.cc,haha视频,火牛视频 yn111,k8k8.com,whereisip,www.gdosta.org.cn,haha视频,火牛视频 innawoods,ajviewer,haha视频 tom365.com,9c8947,haha视频,火牛视频 haha视频,tom365.com,友链交换 yyets.com,haha视频 9c8996,66bobo,友链交换,haha视频 火牛视频,haha视频,友链交换 www.gpsoo.net,www.faxuan.net,www.zjzs.com,www.cmechina.net,三色网 333se.cc,驯龙高手dm456,友情链接交换,火牛视频,haha视频 www.yyy13.com,www.yinwowo.com,火牛视频,haha视频 www.seseou.com,haole010.com,友情链接买卖,haha视频 yazhoutuse,www.yofoto.cn,www.jhyc.cn,baxia,www.eee50.com,qqzb.cc,www.yngbzx.cn,haha视频 www.555kfc.com,www.xs99.com,友链交换,haha视频,火牛视频 www.semm.com,imjpmig,lata-01,kd.wuhan.net.cn,www.q1se.com,友链交换,火牛视频,haha视频 www.cpew.cn,www.daum.net,lata-01,www.yngbzx.cn,www.q1se.com,www.daum.net,1256789,haha视频,火牛视频 haha视频,www.yngbzx.cn,www.cpew.cn,友情链接 英文 dachiyouxiang,www.9999mp.com,www.9999mp.com,sophia cahill,www.74eee.com,ca1835,66814.com,友链交换,haha视频,火牛视频 www.qqq258.com,www.74eee.com,www.xunbo.cc,友链交换,haha视频,火牛视频 www.tubecao.com,dxperience,www.dde8.com,haha视频 www.cpew.cn,www.q1se.com,lata-01,www.cpew.cn,www.q1se.com,www.cpew.cn,友链交换,火牛视频,haha视频 haha视频,www.yngbzx.cn,jkforum,havd707 qqzb.cc,www.cnool.net,www.cqpx.cc,火牛视频,haha视频 haha视频,长春建筑学院教务系统,444ppp,林球立 dachiyouxiang,www.40sqw.com,www.1hhh.com,qqzb.cc,sophia cahill,www.s9797s.com,haha视频,火牛视频 kamikaze love,visualboyadvance, xxjjyy.com,yuanjiao,www.daum.net,haha视频 www.9999mp.com,www.cpew.cn,www.456ai.com,www.kisstudou.com,友链交换,火牛视频,haha视频 ppp13.com,haha视频,火牛视频 ca1835,3u8895,ca1290,ca4111,www.678mmm.com,masa-c,11aabb.com,友链交换,haha视频,火牛视频 ca1835,haha视频,火牛视频 白城师范学院贴吧,江泽名,百世元婴,haha视频 www.gdosta.org.cn,haha视频,火牛视频 haha视频,火牛视频 www.97se.com,haha视频 友链交换,haha视频 www.75zzz.com,www.52cp.cn,9c8950,友链交换,haha视频 www.84qqq.com,www.h4610.com,www.dy2018.net,jkforum,84qqq.com,haha视频,火牛视频 kkxxse.com,haha视频 www.kkxxse.com,ca1816,www.aaa54.com,truffe,www.k17.cc,友链交换 大连枫叶职业技术学院,友情链接的作用 www.ddd13.com,www.44fang.com,www.51zxw.net,mkdv-02 www.1k100.com,www.htsc.com.cn,www.789mmm.com,www.picchealth.com,www.dytt8.net,www.88xoxo.com,友链交换 www.44fang.com,翁其钊,haha视频 www.daum.net,道姑妙妙,haha视频 19ise.com,haha视频 www.cqpx.cc,www.yofoto.cn,haha视频 3u8547,友情链接的作用,haha视频 www.cmechina.net,3u8813,roxane hayward,友链交换,haha视频,火牛视频 www.bxwx.org,www.44fang.com,www.k8k8.com,江苏大学信息门户,友链交换,haha视频 viper12a,unfccc,66814,haha视频 www.88xoxo.com,www.k8k8.com,haha视频 www.souhu.com,www.tubecao.com,roxane hayward,友链交换,haha视频 www.bv2008.cn,友情链接的作用,haha视频,火牛视频 haha视频,火牛视频 9c8836,火牛视频,haha视频 www.b aidu.com,www.yantasy.com,mycoolboy,友链交换,haha视频,火牛视频 h-a-o 薅羊毛的薅,haha视频 www.84qqq.com,友链交换,haha视频 www.40sqw.com,haha视频,火牛视频跑路了吗 www.jhyc.cn,www.444kk.com,www.zhaokao.net,www.zhaokao.com,友链交换 www.yofoto.cn,haha视频 chunnuanhuakaixingbayouni,友链交换,haha视频 pppd-175,友情链接交换,haha视频 www.gpsoo.net,www.haole55.com,haha视频,火牛视频 www.gpsoo.net,www.haole55.com,haha视频,火牛视频 haha视频,火牛视频,火牛视频跑路了吗 武汉音乐学院官网,haha视频,火牛视频跑路了吗 www.jhyc.cn,陈玖福,haha视频 www.19ttt.com,友链交换,火牛视频绑定支付宝安全吗 www.789mmm.com,www.jhyc.cn,火牛视频刷邀请软件,求教程 www.44fang.com,iptd-651,北京科技大学天津学院,火牛视频代刷 www.yofoto.cn,haha视频,火牛视频是不是骗局 xf.faxuan.net,haha视频,火牛视频怎么刷邀请 www.k17.cc,www.1hhh.com,candle june,mine_清翼,友链交换,火牛视频代刷软件 www.44fang.com,www.xunbo.cc,www.75zzz.com,www.dde8.com,友链交换,haha视频 haha视频,火牛视频,火牛视频跑路了吗 www.dde8.com,www.11aabb.com,www.b aidu.com,www.h4610.com,www.49vv.com,www.8008205555,yezimei,www.k8k8.com,www.sac.net.cn,www.kkxxse.com,www.ddd13.com,www.cm68.com,www.yinwowo.com,49vv.com,www.haole15.com,www com,haha视频 www.777vk.com,友情链接 英文,火牛视频吧913 9c8996,友链交换,haha视频 www.xici.net,haha视频,火牛视频 www.haole04.com,www.04jjj.com,haha视频 友链交换,haha视频,火牛视频 k17.cc,www.1hhh.com,火牛视频,haha视频 www.k8k8.com,www.84qqq.com,友链交换,haha视频 浙江万里学院moodle,haha视频,火牛视频 9c8814,www49vv.com,guitarpro5,3edyy,4444.kk.com,9c8996,daum.net,haha视频,火牛视频 阿尔卑斯牧场物语,haha视频,火牛视频跑路了吗 www.b aidu.com,k8k8.com,aidu.com,9c8921,友链交换,haha视频,火牛视频 友情链接买卖,haha视频,火牛视频跑路了吗 www.b aidu.com,aidu.com,9c8921,demonophobia,道姑妙妙,haha视频,火牛视频 www.huangse.com,haha视频,火牛视频跑路了吗 www.40sqw.com,kd.wuhan.net.cn,yezimei,www.haole15.com,masa-c,友链交换,haha视频,火牛视频 浙江金融职业学院,haha视频,火牛视频 www.xinkebiao.com.cn,yezimei,274300,友链交换,haha视频 zhuxianduowan,k8k8.com,9c8950,haha视频,火牛视频 www.cmechina.net,火牛视频,haha视频 kd.wuhan.net.cn,xxjjyy.com,coscoqd,www.yofoto.cn,xxjjyy.com,友链交换 22eee.net,www.1234567.com,pppd-175,haha视频 www.ppp444.com,dachiyouxiang,秋道取风,haha视频 pgd-426,友链交换,haha视频 www.yyy13.com,火牛视频,haha视频 东北大学就业信息网,haha视频,火牛视频 kd.wuhan.net.cn,www.jhyc.cn,dingxiangwuyuetian,友链交换,haha视频 火牛视频跑路了吗,haha视频 火牛视频,haha视频,火牛视频跑路了吗 haha视频,友链交换,火牛视频跑路了吗 www.09955.com,ca1477,kkxxse.com,haha视频,火牛视频 www.haole04.com,mide031,www.04jjj.com,innawoods,haha视频,火牛视频 www.qqq258.com,qqq258,ca1477,www.09955.com,oboni,友链交换,haha视频,火牛视频 qqq258.com,闲坐仙园,友链交换,火牛视频能提现吗 www.8008205555,qqq258.com,www.jhyc.cn,火牛视频怎么样赚钱 www.s9797s.com,www.xs99.com,haha视频,火牛视频贴吧 www.9999mp.com,友链交换,haha视频,火牛视频能赚钱吗 www.44fang.com,www.zhaokao.com,火牛视频跑路,火牛视频跑路了,火牛视频跑路了吗 www.33bbb.com,www.8008205555,100bbb.com,友链交换,haha视频,火牛视频 火牛视频怎么解除绑定,火牛视频吧913 www.tubecao.com,www.cmechina.net,www.dde8.com,www.k17.cc,haha视频,火牛视频,火牛视频微信激活码,火牛视频客服电话多少 www.haole010.com,www.seseou.com,www.8008205555,www.haole17.com,www.haole12.com,友链交换,火牛视频手机验证出错,火牛视频官网是真的吗 sayu-02,艺校的秘密,火牛视频苹果用不了,火牛视频解冻结 manbetx.cc,googims,友情链接交换,火牛视频,haha视频,火牛视频出多久了? www.cpew.cn,www.jhyc.cn,www.kkxxse.com,www.tubecao.com,www.bv2008.cn,www.sdcp.cn,火牛视频怎么样会火吗,友情链接 英文 coscoqd,9c8950,9c8947,manbetx.cc,友链交换,火牛视频客服电话多少,火牛视频什么时候提现 www.dytt8.net,hotavxxx.com,火牛视频官方邀请码,火牛视频客服群 shishangqiyi,haha视频,火牛视频为什么提现失败,火牛视频微信群激活码 www.yinwowo.com,haha视频,火牛视频客服怎么联系,火牛视频为什么提现不了,火牛火牛视频邀请码彬哥给你视频邀请码 东英吉利大学,火牛视频邀请码彬哥送你,火牛视频怎么提现失败,火牛视频官方客服