Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill in color of UTF-8 star

Tags:

css

css-shapes

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">&#9734;&#9734;&#9734;&#9734;</p>
like image 693
Casey Avatar asked May 22 '16 22:05

Casey


People also ask

How do you make a red star in HTML?

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.

What is the UTF-8 in HTML?

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.

What UTF-8 stands for?

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.


2 Answers

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">&#9733;</span>
like image 73
PaulBGD Avatar answered Oct 04 '22 12:10

PaulBGD


Why not use &#9733; or &#x2605; 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>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
</div>

And by using pseudo elements, you can even add functionality such as a 5 star rating system.

like image 32
jbutler483 Avatar answered Oct 04 '22 13:10

jbutler483