WEB前端 网页图标

本文是学习笔记,只是记录,并非原创。

网页图标的几种方式比较

css spritefont & htmlfont & css
原理背景图片定位@font-face
兼容性支持支持低版本IE不支持
图标颜色丰富单一
缩放失真不失真
后期维护困难简单

css sprite
通过background-image和background-position进行切割


font&html
引入字体文件,利用css伪类添加图标 || 在标签中直接写图标编码

@font-face {
  font-family: 'icomoon';
  src:  url('../fonts/icomoon.eot?lyboi0');/*兼容IE9*/
  src:  url('../fonts/icomoon.eot?lyboi0#iefix') format('embedded-opentype'),/*?#iefix解决IE6-8图标无法显示问题*/
    url('../fonts/icomoon.ttf?lyboi0') format('truetype'),
    url('../fonts/icomoon.woff?lyboi0') format('woff'),
    url('../fonts/icomoon.svg?lyboi0#icomoon') format('svg');
  font-weight: normal;
  font-style: normal;
}

.icon {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon:before{
    content:'\图标代码';
}


<span class="icon">&#xe920</span>

html&css
添加class进行添加图标

@font-face {
  font-family: 'icomoon';
  src:  url('../fonts/icomoon.eot?lyboi0');
  src:  url('../fonts/icomoon.eot?lyboi0#iefix') format('embedded-opentype'),
    url('../fonts/icomoon.ttf?lyboi0') format('truetype'),
    url('../fonts/icomoon.woff?lyboi0') format('woff'),
    url('../fonts/icomoon.svg?lyboi0#icomoon') format('svg');
  font-weight: normal;
  font-style: normal;
}

.icon {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-heart:before {
  content: "\e900";
}

<div class="col-md-2">
     <span class="icon icon-truck"></span>
</div>

图标资源网站 icomoon.in


syj 2016.8.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值