search
HomeWeb Front-endHTML Tutorial页面中图标的使用 - 要饭的

 

  之前说要整理这块内容,分享给大家,工作原因,直到现在,赶上清明宅在家里,赶紧整理出来与大家分享。


精灵图(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>

 


先上几个图标网站,因为下面要介绍字体图标了:


字体图标在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;"> 注意:&#xfa21; 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
维护成本  比较困难 简单 简单
颜色 丰富 色彩单一 色彩单一
缩放 失真 清晰 清晰



 

 

 

 

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

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,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

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

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

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

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

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

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

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

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

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

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

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

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools