如何使用 CSS 创建简单的"星级评分"外观?

cssweb developmentfront end technology更新于 2025/11/27 20:28:17

要使用 CSS 创建简单的星级评分外观,代码如下: −

示例

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      margin: 30px;
   }
   .fa {
      font-size: 30px;
      color: grey;
   }
   .rated {
      color: rgb(255, 0, 0);
      border: 2px solid yellow;
   }
</style>
</head>
<body>
<h1>Star Rating Example</h1>
<span class="fa fa-star rated"></span>
<span class="fa fa-star rated"></span>
<span class="fa fa-star rated"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
</body>
</html>

输出

上述代码将产生以下输出 −


相关文章


有用资源