纯CSS星星打分

来源:https://www.sucaihuo.com/js/2308.html 2017-07-04 20:12浏览(2088) 收藏

一款纯CSS星星打分特效,除了引入了font-awesome的字体图标外,没有任何的javascript,可以自由控制加星或减星来加分和减分,星星的样式也可以自由调整,喜欢就直接拿来用吧。
纯CSS星星打分
分类:其它特效 > 星星打分 难易:入门级
查看演示 下载资源 下载积分: 10 积分

页面的head部分先设置好星星的样式,颜色、是否是选中状态等,可以自由调整,代码如下:

h1 {
  font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;
  font-size: 30px;
  font-weight: 500;
}
.star-rating {
  font-family: 'FontAwesome';
  margin: 50px auto;
}
.star-rating > fieldset {
  border: none;
  display: inline-block;
}
.star-rating > fieldset:not(:checked) > input {
  position: absolute;
  top: -9999px;
  clip: rect(0, 0, 0, 0);
}
.star-rating > fieldset:not(:checked) > label {
  float: right;
  width: 1em;
  padding: 0 .05em;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  font-size: 200%;
  color: #26c7fc;
}
.star-rating > fieldset:not(:checked) > label:before {
  content: '\f006  ';
}
.star-rating > fieldset:not(:checked) > label:hover,
.star-rating > fieldset:not(:checked) > label:hover ~ label {
  color: #26c7fc;
  text-shadow: 0 0 3px #26c7fc;
}
.star-rating > fieldset:not(:checked) > label:hover:before,
.star-rating > fieldset:not(:checked) > label:hover ~ label:before {
  content: '\f005  ';
}
.star-rating > fieldset > input:checked ~ label:before {
  content: '\f005  ';
}
.star-rating > fieldset > label:active {
  position: relative;
  top: 2px;
}
body {
  background: #262829;
  color: #95a5a6;
  font-family: 'Raleway';
  text-align: center;
}
body p {
  font-size: 1.6em;
  margin: auto;
  width: 80%;
}
body a {
  color: #26c7fc;
}

页面的body部分先要引入font-awesome.4.6.0.css来显示星星的图标,然后设置好显示的容器即可,代码如下:

<link rel="stylesheet" type="text/css" href="css/font-awesome.4.6.0.css">
<div class="star-rating">
  <fieldset>
    <input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="卓越">五星</label>
    <input type="radio" id="star4" name="rating" value="4" /><label for="star4" title="优秀">四星</label>
    <input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="良好">三星</label>
    <input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="中等">二星</label>
    <input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="很差">一星</label>
  </fieldset>
</div>
<h1>纯CSS星星打分</h1>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2