Skip to content

Instantly share code, notes, and snippets.

@alex-boom
Last active June 4, 2019 07:47
Show Gist options
  • Save alex-boom/ffa5c0b1a452b8379088658f3fb6b8b6 to your computer and use it in GitHub Desktop.
Save alex-boom/ffa5c0b1a452b8379088658f3fb6b8b6 to your computer and use it in GitHub Desktop.
star-raiting-fontawesome
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
$star: "\f005";
$star-half: "\f123";
$star-o: "\f006";
.star-rating-container {
font-family: icomoon;
font-size: 28px;
color: #ffbe00;
position: relative;
// Contain width to width of stars.
display: inline-block;
}
.star-rating {
&:before {
content: $star$star$star$star$star
}
}
.star-rating-on {
position: relative;
z-index: 10;
overflow: hidden;
// IE: prevent stars from wrapping.
white-space: nowrap;
}
.star-rating-off {
position: absolute;
top: 0;
left: 0;
color: #eee;
}
[data-sr^="0"] {
&:before {
content: $star-o;
}
&:after {
content: $star-o $star-o $star-o $star-o;
}
}
[data-sr="0.3"],
[data-sr="0.4"],
[data-sr="0.5"],
[data-sr="0.6"],
[data-sr="0.7"] {
&:before {
content: $star-half;
}
}
[data-sr="0.8"],
[data-sr="0.9"] {
&:before {
content: $star;
}
}
[data-sr^="1"] {
&:before {
content: $star;
}
&:after {
content: $star-o $star-o $star-o $star-o;
}
}
[data-sr="1.3"],
[data-sr="1.4"],
[data-sr="1.5"],
[data-sr="1.6"],
[data-sr="1.7"] {
&:after {
content: $star-half $star-o $star-o $star-o;
}
}
[data-sr="1.8"],
[data-sr="1.9"] {
&:after {
content: $star $star-o $star-o $star-o;
}
}
[data-sr^="2"] {
&:before {
content: $star $star;
}
&:after {
content: $star-o $star-o $star-o;
}
}
[data-sr="2.3"],
[data-sr="2.4"],
[data-sr="2.5"],
[data-sr="2.6"],
[data-sr="2.7"] {
&:after {
content: $star-half $star-o $star-o;
}
}
[data-sr="2.8"],
[data-sr="2.9"] {
&:after {
content: $star $star-o $star-o;
}
}
[data-sr^="3"] {
&:before {
content: $star $star $star;
}
&:after {
content: $star-o $star-o;
}
}
[data-sr="3.3"],
[data-sr="3.4"],
[data-sr="3.5"],
[data-sr="3.6"],
[data-sr="3.7"] {
&:after {
content: $star-half $star-o;
}
}
[data-sr="3.8"],
[data-sr="3.9"] {
&:after {
content: $star $star-o;
}
}
[data-sr^="4"] {
&:before {
content: $star $star $star $star;
}
&:after {
content: $star-o;
}
}
[data-sr="4.3"],
[data-sr="4.4"],
[data-sr="4.5"],
[data-sr="4.6"],
[data-sr="4.7"] {
&:after {
content: $star-half;
}
}
[data-sr="4.8"],
[data-sr="4.9"] {
&:after {
content: $star;
}
}
[data-sr^="5"] {
&:before {
content: $star $star $star $star $star;
}
}
</style>
</head>
<body>
<span class="star-rating-container" data-sr="3.3"></span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment