填写UTF-8星的颜色

时间:2016-05-22 22:18:03

标签: css css-shapes

如何使用CSS填写UTF-8星的背景色(☆)?我尝试使用它,但它只改变了边框颜色:



<p class="rating">&#9734;&#9734;&#9734;&#9734;</p>
&#13;
ENTRYPOINT ["bash", "run.sh"]
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:7)

您可能希望使用固定的星标,例如http://www.fileformat.info/info/unicode/char/2605/index.htm

以下是一个示例: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>

答案 1 :(得分:1)

为什么不使用&#9733;&#x2605;个UTF8字符?

&#13;
&#13;
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;
}
&#13;
<div>
  <span>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
  <span>&#9734;</span>
</div>
&#13;
&#13;
&#13;

通过使用伪元素,您甚至可以添加诸如5星评级系统等功能。

答案 2 :(得分:0)

您可以使用css形状和javascript创建一个带星号(在CSS + JavaScript中)的评级系统。 此代码也适用于其他字符集!

&#13;
&#13;
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);

fieldset, label { margin: 0; padding: 0; }
body{ margin: 20px; }

/****** Style Star Rating Widget *****/

.rating { 
  border: none;
  float: left;
}

.rating > input { display: none; } 
.rating > label:before { 
  margin: 5px;
  font-size: 1.25em;
  font-family: FontAwesome;
  display: inline-block;
  content: "\f005";
}

.rating > .half:before { 
  content: "\f089";
  position: absolute;
}

.rating > label { 
  color: #ddd; 
 float: right; 
}

/***** CSS Magic to Highlight Stars on Hover *****/

.rating > input:checked ~ label, /* show gold star when clicked */
.rating:not(:checked) > label:hover, /* hover current star */
.rating:not(:checked) > label:hover ~ label { color: #FFD700;  } /* hover previous stars in list */

.rating > input:checked + label:hover, /* hover current star when changing rating */
.rating > input:checked ~ label:hover,
.rating > label:hover ~ input:checked ~ label, /* lighten current selection */
.rating > input:checked ~ label:hover ~ label { color: #FFED85;  } 
&#13;
<fieldset class="rating">
    <input type="radio" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="Awesome - 5 stars"></label>
    <input type="radio" id="star4half" name="rating" value="4 and a half" /><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
    <input type="radio" id="star4" name="rating" value="4" /><label class = "full" for="star4" title="Pretty good - 4 stars"></label>
    <input type="radio" id="star3half" name="rating" value="3 and a half" /><label class="half" for="star3half" title="Meh - 3.5 stars"></label>
    <input type="radio" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
    <input type="radio" id="star2half" name="rating" value="2 and a half" /><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
    <input type="radio" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="Kinda bad - 2 stars"></label>
    <input type="radio" id="star1half" name="rating" value="1 and a half" /><label class="half" for="star1half" title="Meh - 1.5 stars"></label>
    <input type="radio" id="star1" name="rating" value="1" /><label class = "full" for="star1" title="Sucks big time - 1 star"></label>
    <input type="radio" id="starhalf" name="rating" value="half" /><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
&#13;
&#13;
&#13;