进阶篇之纯css+字体实现五角星(半颗星)评分
1.前言
之前写了一篇实现五角星打分效果的demo。这个demo用来实现打分效果绰绰有余,那么有时候我们在统计评分的时候,就会有半颗星或者1/3颗星星这样的那要如何实现呢?来来来,纯字体+css实现!
2.详情
1.下载字体 webFontIcon 我不会把压缩文件上传,会的童鞋可以教教我,感谢赐教,这样我就可以把字体上传以供大家下载了。
2.css样式
.cleanfloat::after{display: block; clear: both; content:""; visibility: hidden; height: 0;} *{margin:0; padding:0;} /*字体路径按照你的路径去修改*/ @font-face { font-family: 'AlluraRegular'; src: url('../common/webFontIcon/websymbols/fonts/websymbols-regular-webfont.eot'), url('../common/webFontIcon/websymbols/fonts/websymbols-regular-webfont?#iefix') format('embedded-opentype'), url('../common/webFontIcon/websymbols/fonts/websymbols-regular-webfont.woff') format('woff'), url('../common/webFontIcon/websymbols/fonts/websymbols-regular-webfont.ttf') format('truetype'), url('../common/webFontIcon/websymbols/fonts/websymbols-regular-webfont.svg#AlluraRegular') format('svg'); } .starFive span {display: block;float: left;font-size: 25px; font-family: 'AlluraRegular'; text-align: center;color: #888;width: 27px;height: 33px;line-height: 33px; margin-right: 5px;position: relative;overflow: hidden;white-space: pre; } .starFive span:before {position: absolute; left: 0;top: 0;display: block;width: 50%; content: attr(data-content);overflow: hidden;color: #F63; } .sF1 span:before{width: 70%;} .sF2 span:before{width: 50%;} .sF3 span:before{width: 40%;} .starFive .org_star {color: #F63;} .starFive b {font-weight: normal; line-height: 40px; font-size: 25px;color: #888;margin-left: 10px; }
3.html内容
<div> <p class='cleanfloat starFive sF1'><span class='org_star'>R</span><span class='org_star'>R</span><span class='org_star'>R</span><span class='org_star'>R</span><span data-content='R'>R</span><b>4.7分</b></p> <p class='cleanfloat starFive sF2'><span class='org_star'>R</span><span class='org_star'>R</span><span class='org_star'>R</span><span data-content='R'>R</span><span>R</span><b>3.5分</b></p> <p class='cleanfloat starFive sF3'><span class='org_star'>R</span><span class='org_star'>R</span><span data-content='R'>R</span><span>R</span><span>R</span><b>2.4分</b></p> </div>
4.效果展示
3.总结
这个IE8及以上等其他高版本浏览器都是支持的。是不是很实用的打分?如果是做数据查询的时候,显示这样的打分,就可以用到了。如果觉得哪里需要改进的,还请多多赐教。学无止境,我希望得到大家的批评,才会有进步。一个人孤军奋战,感觉进步的慢。
1. 随笔为作者自己经验以及学习的总结;欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接
2. 如本文对您有帮助请移步右下角,推荐本文,谢谢大家的点赞,因为您的支持是我最大动力;
2. 如本文对您有帮助请移步右下角,推荐本文,谢谢大家的点赞,因为您的支持是我最大动力;
by 苏小苏
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?