Skip to content

Instantly share code, notes, and snippets.

@ktokot
Forked from chriscoyier/dabblet.css
Last active January 3, 2021 16:42
Show Gist options
  • Save ktokot/fe97c8d03d73bff97832a4b516b5d496 to your computer and use it in GitHub Desktop.
Save ktokot/fe97c8d03d73bff97832a4b516b5d496 to your computer and use it in GitHub Desktop.
Ratings Stars
/*
Ratings Stars
(with as little code as possible)
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
}
.rating > span {
display: inline-block;
position: relative;
width: 1.1em;
}
.rating > span:hover,
.rating > span:hover ~ span {
color: transparent;
clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);
}
.rating > span:hover:before,
.rating > span:hover ~ span:before {
content: "\2605";
position: absolute;
left: 0;
color: gold;
}
.halfStyle {
position: relative;
display: inline-block;
font-size: 80px; /* or any font size will work */
color: black; /* or transparent, any color */
overflow: hidden;
white-space: pre; /* to preserve the spaces from collapsing */
}
.halfStyle:before {
display: block;
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 50%;
content: attr(data-content); /* dynamic content for the pseudo element */
overflow: hidden;
color: #f00;
}body { padding: 100px; }
<div class="rating">
<span>☆</span><span>☆</span><span>☆</span><span>☆</span><span class="halfStyle" data-content="\2605">☆</span>
</div>
{"view":"split","fontsize":"90","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment