如何在 Tailwind CSS 中使用星级
来源:dev.to
时间:2024-07-24 20:22:01 139浏览 收藏
编程并不是一个机械性的工作,而是需要有思考,有创新的工作,语法是固定的,但解决问题的思路则是依靠人的思维,这就需要我们坚持学习和更新自己的知识。今天golang学习网就整理分享《如何在 Tailwind CSS 中使用星级》,文章讲解的知识点主要包括,如果你对文章方面的知识点感兴趣,就不要错过golang学习网,在这可以对大家的知识积累有所帮助,助力开发能力的提升。
了解如何使用 tailwind css 轻松实现星级评级!本快速指南将引导您完成将星形图标完美地集成到您的 web 项目中的步骤。通过这个简单的教程提升用户交互和设计美学。
tailwind css 颜色渐变生成器
要将星级评定与 tailwind css 一起使用,您可以创建自定义组件。
<div class="flex items-center"> <span class="text-yellow-400">★</span> <span class="text-yellow-400">★</span> <span class="text-yellow-400">★</span> <span class="text-gray-300">★</span> <span class="text-gray-300">★</span> </div>
使用 heroicons 和 tailwindcss 进行简单的星级评定。
<ul class="flex items-center gap-x-1"> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> </ul>
简单的顺风星级评级与很棒的图标。
<ul class="flex items-center gap-x-1"> <li> <i class="text-yellow-300 far fa-star"></i> </li> <li> <i class="text-yellow-300 far fa-star"></i> </li> <li> <i class="text-yellow-300 far fa-star"></i> </li> <li> <i class="text-yellow-300 far fa-star"></i> </li> <li> <i class="text-yellow-300 far fa-star"></i> </li> </ul>
使用 html 符号代码在 tailwind css 中创建星级评级。
tailwind css 投资组合跟踪器免费和付费模板
<div class="flex items-center"> <!-- 1st star --> <input type="radio" id="star1" name="rating" class="hidden" /> <label for="star1" class="cursor-pointer text-2xl text-yellow-500">★</label> <!-- 2nd star --> <input type="radio" id="star2" name="rating" class="hidden" /> <label for="star2" class="cursor-pointer text-2xl text-yellow-500">★</label> <!-- 3rd star --> <input type="radio" id="star3" name="rating" class="hidden" /> <label for="star3" class="cursor-pointer text-2xl text-yellow-500">★</label> <!-- 4th star --> <input type="radio" id="star4" name="rating" class="hidden" /> <label for="star4" class="cursor-pointer text-2xl text-yellow-500">★</label> <!-- 5th star --> <input type="radio" id="star5" name="rating" class="hidden" /> <label for="star5" class="cursor-pointer text-2xl text-yellow-500">★</label> </div>
带悬停效果的顺风星级评级。
<ul class="flex items-center gap-x-1"> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300 fill-current hover:text-yellow-400" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300 fill-current hover:text-yellow-400" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-yellow-300 hover:text-yellow-400" fill="none" viewbox="0 0 24 24" stroke="currentcolor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> </ul>
创建用户星级评论卡。
<div class="max-w-sm px-4 py-4 rounded-lg shadow"> <div class="px-4 py-4 mb-1 tracking-wide"> <h2 class="mt-1 font-semibold text-gray-800">106 Users reviews</h2> <div class="px-8 pb-3 -mx-8 border-b"> <div class="flex items-center mt-1"> <div class="w-1/5 tracking-tighter text-gray-500"> <span>5 star</span> </div> <div class="w-3/5"> <div class="w-full h-2 bg-gray-300 rounded-lg"> <div class="w-7/12 h-2 bg-yellow-600 rounded-lg"></div> </div> </div> <div class="w-1/5 pl-3 text-gray-700"> <span class="text-sm">51%</span> </div> </div> <div class="flex items-center mt-1"> <div class="w-1/5 tracking-tighter text-gray-500"> <span>4 star</span> </div> <div class="w-3/5"> <div class="w-full h-2 bg-gray-300 rounded-lg"> <div class="w-1/5 h-2 bg-yellow-600 rounded-lg"></div> </div> </div> <div class="w-1/5 pl-3 text-gray-700"> <span class="text-sm">17%</span> </div> </div> <div class="flex items-center mt-1"> <div class="w-1/5 tracking-tighter text-gray-500"> <span>3 star</span> </div> <div class="w-3/5"> <div class="w-full h-2 bg-gray-300 rounded-lg"> <div class="w-3/12 h-2 bg-yellow-600 rounded-lg"></div> </div> </div> <div class="w-1/5 pl-3 text-gray-700"> <span class="text-sm">19%</span> </div> </div> <div class="flex items-center mt-1"> <div class="w-1/5 tracking-tighter text-gray-500"> <span>2 star</span> </div> <div class="w-3/5"> <div class="w-full h-2 bg-gray-300 rounded-lg"> <div class="w-1/5 h-2 bg-yellow-600 rounded-lg"></div> </div> </div> <div class="w-1/5 pl-3 text-gray-700"> <span class="text-sm">8%</span> </div> </div> <div class="flex items-center mt-1"> <div class="w-1/5 tracking-tighter text-gray-500"> <span>1 star</span> </div> <div class="w-3/5"> <div class="w-full h-2 bg-gray-300 rounded-lg"> <div class="w-2/12 h-2 bg-yellow-600 rounded-lg"></div> </div> </div> <div class="w-1/5 pl-3 text-gray-700"> <span class="text-sm">5%</span> </div> </div> </div> </div> <div class="w-full px-4"> <h3 class="font-medium tracking-tight">Review this item</h3> <ul class="flex items-center gap-x-1"> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-yellow-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-yellow-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-yellow-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-yellow-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> <li> <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-yellow-300" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z" /> </svg> </li> </ul> <p class="py-1 text-sm text-gray-700">Plz Give your star rating 1 to 5.</p> </div> </div>
以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于文章的相关知识,也可关注golang学习网公众号。
声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
232 收藏
-
215 收藏
-
264 收藏
-
335 收藏
-
283 收藏
-
416 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 541次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 506次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习