惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - sharmy

[转]快速理解数据库中的索引(Indexes in Database) mysql数据库中的索引与优化、理解与用途 MySQL锁机制 经典mysql 语句收录 mysql查找执行效率慢的SQL语句 Lighttpd 编写lighttpd插件 Lighttpd 配置与性能优化 Apache SSL Module 介绍,原理及安装 ulimit 修改常见服务器的banner mysql M/S配置小记 MySQL触发器自动更新memcache[转] php效率高写法 memcache在大型网站的应用策略【转】 开发大型高负载类网站应用的几个要点[转] asp.net性能常用优化 转 缓存理解 转 如何利用客户端缓存对网站进行优化?
用css sprites(图像拼合技术)优化css加快网站速度[转]
sharmy · 2009-02-23 · via 博客园 - sharmy

一般说来客户端对服务器端进行一次请求就要消耗0.2s左右。如果一个网站的图片,特别是网页素材较多的情况下, 于服务器之间的延迟就很大。利用CSS 图片拼合 (CSS sprites) 可有效降低图片文件的 HTTP 连接请求数。 多个图片将以一定间距合并为一个大图片文件。页面中使用这些图片的元素将利用 background-position 这一 CSS 属性来显示拼合图片中的指定位置。
例子:

<div class=”max”>最大化</div>
<div class=”min”>最小化</div>

这两个class都使用同一个图片:

.min, max {
width:16px;
height:16px;
background-image:url(http://developer.yahoo.com/yui/build/assets/skins/sam/sprite.png);
background-repeat: no-repeat; //我们并不想让它平铺
text-indent:-999em; //隐藏文本的一种方法
}

效果如下:

最大化最小化
最大化最小化
我们看到一团灰,没错,因为我们还没有指定background-position,默认为 0 0,可以看下 sprite.png , 处于这个位置正是灰块。好了,我们要找到代表最大化的加号和代表最小化的减号的位置找出来。经过测量,最大化按钮位于Y轴的350px处,最小化按钮位于 Y轴400px处。想一想我们如何才能让它们能够显示出来呢,明显,要向上提升sprite.png,得到代码如下:

.max {
background-position: 0 -350px;
}
.min {
background-position: 0 -400px;
}

就是这么简单,不过相信最麻烦的就是定位像素的问题,没事推荐个网站Web performance.这个能很轻松的帮你合成一张图片并帮你定位background-position的值。