【问题标题】:how to write CSS for Star Rating in this scenario?在这种情况下如何为 Star Rating 编写 CSS?
【发布时间】:2016-07-01 05:14:45
【问题描述】:

陷入半星评级问题 CSS。我参考了http://codepen.io/mrk1989/pen/mLeHJ

我的 Star 显示的 Html 结构是这样的

<ul class="rateChange">
  <li>
    <input type="radio" id="rating10" name="rating" value="10" />
    <label for="rating10" title="5 stars"></label>
    <input type="radio" id="rating9" name="rating" value="9" />
    <label class="half" for="rating9" title="4 1/2 stars"></label>
  </li>
  <li>
    <input type="radio" id="rating8" name="rating" value="8" />
    <label for="rating8" title="4 stars"></label>
    <input type="radio" id="rating7" name="rating" value="7" />
    <label class="half" for="rating7" title="3 1/2 stars"></label>
  </li>
  <li>
    <input type="radio" id="rating6" name="rating" value="6" />
    <label for="rating6" title="3 stars"></label>
    <input type="radio" id="rating5" name="rating" value="5" />
    <label class="half" for="rating5" title="2 1/2 stars"></label>
  </li>
  <li>
    <input type="radio" id="rating4" name="rating" value="4" />
    <label for="rating4" title="2 stars"></label>
    <input type="radio" id="rating3" name="rating" value="3" />
    <label class="half" for="rating3" title="1 1/2 stars"></label>
  </li>
  <li>
    <input type="radio" id="rating2" name="rating" value="2" />
    <label for="rating2" title="1 star"></label>
    <input type="radio" id="rating1" name="rating" value="1" />
    <label class="half" for="rating1" title="1/2 star"></label>
  </li>
</ul>

在我的情况下,星星位于 ul li 标签下,以及如何更改我的 css 以获取上面链接中给出的所有 css 功能(例如单击所有以前和当前的星星为 ON 并且悬停所有以前和当前的星星开始显示悬停效果)。

这是我正在做某事的 jsfiddle 链接https://jsfiddle.net/ae0ypksv/ 无法实现全部功能。

非常感谢您的帮助..!!谢谢

【问题讨论】:

  • 你有所有的代码,你还想要什么?
  • @Evan Trimboli 是的,我有一个代码,问题是,星星是通过 ng-repeat 生成的,我尝试了很多来调整 css,但我不太擅长 css 来调整。

标签: css sass scss-lint


【解决方案1】:

您必须将所有输入/标签放在一个 &lt;li&gt; 中,例如 this

<h1>Half Star Rating Change Senirow</h1>

<ul class="rateChange">
  <li>
    <input type="radio" id="rating10" name="rating" value="10" />
    <label for="rating10" title="5 stars"></label>
    <input type="radio" id="rating9" name="rating" value="9" />
    <label class="half" for="rating9" title="4 1/2 stars"></label>

    <input type="radio" id="rating8" name="rating" value="8" />
    <label for="rating8" title="4 stars"></label>
    <input type="radio" id="rating7" name="rating" value="7" />
    <label class="half" for="rating7" title="3 1/2 stars"></label>

    <input type="radio" id="rating6" name="rating" value="6" />
    <label for="rating6" title="3 stars"></label>
    <input type="radio" id="rating5" name="rating" value="5" />
    <label class="half" for="rating5" title="2 1/2 stars"></label>

    <input type="radio" id="rating4" name="rating" value="4" />
    <label for="rating4" title="2 stars"></label>
    <input type="radio" id="rating3" name="rating" value="3" />
    <label class="half" for="rating3" title="1 1/2 stars"></label>

    <input type="radio" id="rating2" name="rating" value="2" />
    <label for="rating2" title="1 star"></label>
    <input type="radio" id="rating1" name="rating" value="1" />
    <label class="half" for="rating1" title="1/2 star"></label>
  </li>
</ul>

【讨论】:

  • 星星(输入和标签)是通过 ng-repeat 生成的,即基于用户传递的内容。所以所有的输入和标签都在 li 下,所以我怎样才能使用 css sudeo 类来实现这个功能。
【解决方案2】:

这是我已经解决的解决方案,请检查它...

body {
    margin: 5%; 
    text-align: center;
    background:  aliceblue;
    color:  darkred; 
}
h1 {
    font-size: 2em; 
    margin-bottom: .5rem;
}

/* Ratings widget */
.rate {
    display: inline-block;
    border: 0;
}
/* Hide radio */
.rate > input {
    display: none;
}
/* Order correctly by floating highest to the right */
.rate > label {
    float: right;
}
/* The star of the show */
.rate > label:before {
    display: inline-block;
    font-size: 50px;
    padding: .3rem .2rem;
    margin: 0;
    cursor: pointer;
    font-family: FontAwesome;
    content: '\2605'; /* full star */
}

/* Zero stars rating */
.rate > label:last-child:before {
    content: '\2605' ; /* empty star outline */
}

input:checked ~ label, /* color current and previous stars on checked */
label:hover, label:hover ~ label { color: #73B100;  } /* color previous stars on hover */

/* Hover highlights */
input:checked + label:hover, input:checked ~ label:hover, /* highlight current and previous stars */
input:checked ~ label:hover ~ label, /* highlight previous selected stars for new rating */
label:hover ~ input:checked ~ label /* highlight previous selected stars */ { color: #A6E72D;  } 
<html>
<head>
<title>Rating</title>
<link type="text/css" href="style.css" rel="stylesheet">

</head>
<body>
<h1>Star Rating By Md.Sabbirul Islam</h1>


<fieldset class="rate">
    <input type="radio" id="rating10" name="rating" value="10" /><label for="rating10" title="5 stars"></label>
    
    <input type="radio" id="rating8" name="rating" value="8" /><label for="rating8" title="4 stars"></label>

    <input type="radio" id="rating6" name="rating" value="6" /><label for="rating6" title="3 stars"></label>

    <input type="radio" id="rating4" name="rating" value="4" /><label for="rating4" title="2 stars"></label>

    <input type="radio" id="rating2" name="rating" value="2" /><label for="rating2" title="1 star"></label>

    <input type="radio" id="rating0" name="rating" value="0" /><label for="rating0" title="No star"></label>
</fieldset>
</body>
</html>

【讨论】:

猜你喜欢
  • 2021-11-30
  • 1970-01-01
  • 2021-05-21
  • 2013-11-03
  • 2012-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多