I attempted to create my own star rating system using HTML and CSS, but encountered issues with its functionality. While solutions like using direction: rtl
or float: right
worked, I am unable to implement them due to constraints related to PHP.
Is there a way to achieve the desired outcome using only CSS and HTML?
$('.stars a').on('click', function(){
$('.stars a').removeClass('active');
$(this).addClass('active');
});
.stars input {
position: absolute;
left: -999999px;
}
.stars a {
display: inline-block;
font-size: 0;
text-decoration: none;
}
.stars a:before {
position: relative;
font-size: 18px;
font-family: 'FontAwesome', serif;
display: block;
content: "\f005";
color: #9e9e9e;
}
.stars a:hover:before,
.stars a:hover ~ a:before,
.stars a.active:before,
.stars a.active ~ a:before {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<p class="stars">
<span>
<a class="star-1" href="#">1</a>
<a class="star-2" href="#">2</a>
<a class="star-3" href="#">3</a>
<a class="star-4" href="#">4</a>
<a class="star-5" href="#">5</a>
</span>
</p>