之前说要整理这块内容,分享给大家,工作原因,直到现在,赶上清明宅在家里,赶紧整理出来与大家分享。
精灵图(CSS sprite)
所谓精灵图,其实就是把几张图拼成一张图。从而在低并发的浏览器上达到快速传输并呈现内容的目的(减少请求)。
- 在用到这些图片的时候,需要引用整张图片然后设定坐标到需要的那张小图上。
- 还有就是:图片根据颜色分组,分成多个文件。每张图只有一种颜色,这样让每张图片变得更小。
- 当然,这根据当前项目来选择适于你的方案。主要根据下面两个属性来处理精灵图:
<span style="color: #008080;">1</span> <span style="color: #800000;">background-image: url("...</span><span style="color: #008000;">/*</span><span style="color: #008000;">.png"); </span><span style="color: #008080;">2</span> <span style="color: #008000;">background-position: 0px 0px; </span><span style="color: #008080;">3</span> <span style="color: #008080;">4</span> <span style="color: #008000;">/* 注意:position的负值情况。 </span><span style="color: #008000;">*/</span>
先上几个图标网站,因为下面要介绍字体图标了:
- > [fortawesome.github.io]
- > [icomoon.io]
- > [阿里图标库]
- > [Font Awesome 3.0]
字体图标在html中的使用
<span style="color: #008080;">1</span> <span style="color: #0000ff;"><span style="color: #800000;">li</span><span style="color: #0000ff;">><span style="color: #800000;">a </span><span style="color: #ff0000;">href</span><span style="color: #0000ff;">=""</span><span style="color: #0000ff;">><span style="color: #800000;">i </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="i-icon"</span><span style="color: #0000ff;">></span>﨡<span style="color: #0000ff;"></span><span style="color: #800000;">i</span><span style="color: #0000ff;">></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span> <span style="color: #008080;">2</span> <span style="color: #008000;"><!--</span><span style="color: #008000;"> 注意:﨡 fa21为16进制 需要&#x </span><span style="color: #008000;">--><br></span></span></span></span>
<span style="color: #008080;"> 1</span> <span style="color: #800000;"> @font-face</span>{ <span style="color: #008080;"> 2</span> <span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> "my-icon" </span><span style="color: #008080;"> 3</span> <span style="color: #0000ff;"> src: url("..</span><span style="color: #008000;">/*</span><span style="color: #008000;">.eot"); </span><span style="color: #008080;"> 4</span> <span style="color: #008000;"> /* ie低版本浏览器需要加'?' 否则可能回报404错误 </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;"> src: url("../ *.eot?") format("embedded-opentype") </span><span style="color: #008080;"> 6</span> <span style="color: #0000ff;"> ,url("../ *.woff") format("woff") </span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;"> ,url("../ *.ttf") format("truetype") </span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;"> ,url("../ *.svg") format("svg")</span>; <span style="color: #008080;"> 9</span> <span style="color: #ff0000;"> font-weight</span>:<span style="color: #0000ff;"> normal</span>; <span style="color: #008080;">10</span> <span style="color: #ff0000;"> font-style</span>:<span style="color: #0000ff;"> normal</span>; <span style="color: #008080;">11</span> } <span style="color: #008080;">12</span> <span style="color: #800000;"> .i-icon</span>{ <span style="color: #008080;">13</span> <span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> "my-icon"</span>; <span style="color: #008080;">14</span> <span style="color: #ff0000;"> font-style</span>:<span style="color: #0000ff;"> normal</span>; <span style="color: #008080;">15</span> <span style="color: #ff0000;"> font-weight</span>:<span style="color: #0000ff;"> normal</span>; <span style="color: #008080;">16</span> <span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 26px</span>; <span style="color: #008080;">17</span> <span style="color: #ff0000;"> -webkit-font-smoothing</span>:<span style="color: #0000ff;"> antialiased</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">消除锯齿</span><span style="color: #008000;">*/</span> <span style="color: #008080;">18</span> <span style="color: #ff0000;"> -moz-osx-font-smoothing</span>:<span style="color: #0000ff;"> grayscale</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">消除锯齿</span><span style="color: #008000;">*/</span> <span style="color: #008080;">19</span> }
字体图标在css中的使用
<span style="color: #008080;">1</span> <span style="color: #0000ff;"><span style="color: #800000;">li</span><span style="color: #0000ff;">><span style="color: #800000;">i </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="icon icon-magic"</span><span style="color: #0000ff;">></span><span style="color: #800000;">i</span><span style="color: #0000ff;">></span><span style="color: #800000;">li</span><span style="color: #0000ff;">></span> <span style="color: #008080;">2</span> <span style="color: #008000;"><!--</span><span style="color: #008000;"> 直接引用class name </span><span style="color: #008000;">--></span></span></span>
<span style="color: #800000;">@font-face </span>{<span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> "myfont"</span>;<span style="color: #ff0000;"> src</span>:<span style="color: #0000ff;"> url("../ *.eot")</span>;<span style="color: #ff0000;"> src</span>:<span style="color: #0000ff;"> url("../ *.eot?#iefix") format("embedded-opentype"), url("../ *.woff") format("woff"), url("../ *.ttf") format("truetype"), url("../ *.svg") format("svg")</span>;<span style="color: #ff0000;"> font-weight</span>:<span style="color: #0000ff;"> normal</span>;<span style="color: #ff0000;"> font-style</span>:<span style="color: #0000ff;"> normal</span>; }<span style="color: #800000;"> .icon </span>{<span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> "myfont"</span>;<span style="color: #ff0000;"> font-weight</span>:<span style="color: #0000ff;"> normal</span>;<span style="color: #ff0000;"> font-style</span>:<span style="color: #0000ff;"> normal</span>;<span style="color: #ff0000;"> -webkit-font-smoothing</span>:<span style="color: #0000ff;"> antialiased</span>;<span style="color: #ff0000;"> -moz-osx-font-smoothing</span>:<span style="color: #0000ff;"> grayscale</span>; }<span style="color: #800000;"> .icon-magic:before </span>{<span style="color: #ff0000;"> content</span>:<span style="color: #0000ff;"> "\c210"</span>; }
各种方式对比
精灵图 | 在html中 | 在css中 | |
原理 | 使用图片定位 | @font-face | @font-face |
兼容 | + | + | 不支持低版本IE |
维护成本 | 比较困难 | 简单 | 简单 |
颜色 | 丰富 | 色彩单一 | 色彩单一 |
缩放 | 失真 | 清晰 | 清晰 |

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
