How can I use CSS to fill in the background color of a UTF-8 star (☆)? I tried using this, but it only changes the border color:
.rating {
color: #f70;
}
<p class="rating">☆☆☆☆</p>
The sup tag defines superscript text which appears half a character above the normal line. So the star mark will appear little above the normal text label.
UTF-8 (UCS Transformation Format 8) is the World Wide Web's most common character encoding. Each character is represented by one to four bytes. UTF-8 is backward-compatible with ASCII and can represent any standard Unicode character.
UTF stands for "UCS (Unicode) Transformation Format". The UTF-8 encoding can be used to represent any Unicode character. Depending on a Unicode character's numeric value, the corresponding UTF-8 character is a 1, 2, or 3 byte sequence.
You probably want to use a solid star, like http://www.fileformat.info/info/unicode/char/2605/index.htm
Here's an example: http://codepen.io/PaulBGD/pen/reXWvX
#star {
font-size: 128px;
color: yellow;
/* Some sort of border */
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
<span id="star">★</span>
Why not use ★
or ★
UTF8 characters?
div {
padding: 2px;
background: cornflowerblue;
border: 2px solid lightgray;
border-radius: 2px;
display: inline-block;
}
div span {
position: relative;
}
div span:before {
content: "\2605";
position: absolute;
transition:all 0.4s;
color: gold;
}
div span:hover ~ span:before {
content: "\2606";
color: black;
}
<div>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
And by using pseudo elements, you can even add functionality such as a 5 star rating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With