Change star rating on hover

后端 未结 4 1595
南旧
南旧 2021-01-08 01:09

I use this code to display stars:

4条回答
  •  别那么骄傲
    2021-01-08 02:12

    You expected thing is possible with only css. Because css rule is applied for next sibling not for previous. You should also use JQuery.

    But you can do it using following trick using css:

    .rating input { display: none; } 
    .rating label:before { 
      margin: 5px;
      font-size: 1.25em;
      font-family: FontAwesome;
      display: inline-block;
      content: "\f005";
    }
    
    li {list-style:none;
    direction:rtl;
    text-align: left;}
    
    .rating label { 
      color: #ffffd;
    }
    
    /***** CSS to Highlight Stars on Hover *****/
    
    .rating input:checked ~ label, /* show gold star when clicked */
    .rating:not(:checked) label:hover, /* hover current star */
    .rating:not(:checked) label:hover ~ label { color: #FFD700;  } /* hover previous stars in list */
    
    .rating input:checked + label:hover, /* hover current star when changing rating */
    .rating input:checked ~ label:hover,
    .rating label:hover ~ input:checked ~ label, /* lighten current selection */
    .rating input:checked ~ label:hover ~ label { color: #FFED85;  } 

提交回复
热议问题