第一步:使用font-face声明字体
@font-face {font-family: ‘iconfont‘; src: url(‘iconfont.eot‘); /* IE9*/ src: url(‘iconfont.eot?#iefix‘) format(‘embedded-opentype‘), /* IE6-IE8 */ url(‘iconfont.woff‘) format(‘woff‘), /* chrome、firefox */ url(‘iconfont.ttf‘) format(‘truetype‘), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ url(‘iconfont.svg#uxiconfont‘) format(‘svg‘); /* iOS 4.1- */ }
第二步:定义使用iconfont的样式
.iconfont{ font-family:"iconfont" !important; font-size:16px;font-style:normal; -webkit-font-smoothing: antialiased; -webkit-text-stroke-width: 0.2px; -moz-osx-font-smoothing: grayscale;}
第三步:挑选相应图标并获取字体编码,应用于页面
<i class="iconfont">3</i>
第四步:字体图标的应用
.checkbox input, .radio input { display: none;} /*inputy隐藏*/ .radio label:before{ content: "\e60e";}/*默认单选框的样式*/ .checkbox label:before{ content: "\f0011";}/*默认复选框的样式*/ .radio label:hover:before {content: "\e60f";}/*鼠标浮动上单选框样式*/ .checkbox label:hover:before {content: "\f0012";}/*鼠标浮动上复选框样式*/ .radio input:checked + label:before { content: "\e60f";}/*鼠标浮点击后单选框样式*/ .checkbox input:checked + label:before { content: "\f0012";}/*鼠标浮点击后复选框样式*/
HTML:
<span class="checkbox"> <input type="checkbox" id="checkbox1" name="ckeckbox" /> <label for="checkbox1" class="iconfont"></label>货币基金 </span> <span class="checkbox"> <input type="checkbox" id="checkbox2" name="ckeckbox" /> <label for="checkbox2" class="iconfont"></label>基金定投 </span>
<span class="radio"><input type="radio" id="radio19" name="radio4" /><label for="radio19" class="iconfont"></label>非常满意 </span> <span class="radio"><input type="radio" id="radio20" name="radio4" /><label for="radio20" class="iconfont"></label>比较满意 </span> <span class="radio"><input type="radio" id="radio21" name="radio4" checked="checked" /><label for="radio21" class="iconfont"></label>一般 </span> <span class="radio"><input type="radio" id="radio22" name="radio4" /><label for="radio22" class="iconfont"></label>不太满意 </span> <span class="radio"><input type="radio" id="radio23" name="radio4" /><label for="radio23" class="iconfont"></label>很不满意 </span>
最终效果展示:
时间: 2024-10-12 21:24:55