Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

html - Half star rating with empty stars and radio buttons

Is it possible to achieve this with radio button labels and font awesome icons? half star rating style I need

The most that I have managed to do is this, using two font awesome icons as radio button labels but I don't want unselected areas to be grey, rather empty star with border just like in the image above: half star rating that I got

Here is my code:

.rate{
  display: inline-block;
  border: 0;
  color: #b0afaf;
}
  
.rate > input{
  display: none;
}

.rate > label {
  float: right;
 }  

.rate > label:before {
  display: inline-block;
  font-size: 1.1rem;
  padding: .3rem .2rem;
  margin: 0;
  cursor: pointer;
  font-family: FontAwesome;
  content: "f005 ";
 }
  
.rate .half:before {
  content: "f089 ";
  position: absolute;
  padding-right: 0;
 }
    
input:checked ~ label,
label:hover, label:hover ~ label {
  color: #dbc00b;
}

input:checked + label:hover, input:checked ~ label:hover,
input:checked ~ label:hover ~ label,
label:hover ~ input:checked ~ label {
  color: #f2ec35;
}
  
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="rate">
  <input type="radio" id="star5" name="rating" value="5" />
  <label for="star5" title="Awesome"></label>
  <input type="radio" id="star4.5" name="rating" value="4.5" />
  <label for="star4.5" class="half"></label>
  <input type="radio" id="star4" name="rating" value="4" />
  <label for="star4"></label>
  <input type="radio" id="star3.5" name="rating" value="3.5" />
  <label for="star3.5" class="half"></label>
  <input type="radio" id="star3" name="rating" value="3" />
  <label for="star3"></label>
  <input type="radio" id="star2.5" name="rating" value="2.5" />
  <label for="star2.5" class="half"></label>
  <input type="radio" id="star2" name="rating" value="2" />
  <label for="star2"></label>
  <input type="radio" id="star1.5" name="rating" value="1.5" />
  <label for="star1.5" class="half"></label>
  <input type="radio" id="star1" name="rating" value="1" />
  <label for="star1"></label>
  <input type="radio" id="star0.5" name="rating" value="0.5" />
  <label for="star0.5" class="half"></label>
</div>
question from:https://stackoverflow.com/questions/65951513/half-star-rating-with-empty-stars-and-radio-buttons

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...