CSS星级评分分离

时间:2016-07-01 06:39:26

标签: html html5 twitter-bootstrap css3 twitter-bootstrap-3

晚安。

大家好,我有一个问题:我的页面中有一个单选按钮星级评估小工具,此时星星彼此接近,我需要将它们分开(填写div的文件)。

HTML

<div class="stars-div">
    <div class="stars">
        <input class="star-input star-5" id="star-5" type="radio" name="star"/>
        <label class="star-icon star-5" for="star-5"></label>                                   
        <input class="star-input star-4" id="star-4" type="radio" name="star"/>
        <label class="star-icon star-4" for="star-4"></label>
        <input class="star-input star-3" id="star-3" type="radio" name="star"/>
        <label class="star-icon star-3" for="star-3"></label>
        <input class="star-input star-2" id="star-2" type="radio" name="star"/>
        <label class="star-icon star-2" for="star-2"></label>
        <input class="star-input star-1" id="star-1" type="radio" name="star"/>
        <label class="star-icon star-1" for="star-1"></label>
    </div>
</div>

CSS

.stars-div {
    padding-top: 9.8%;
    padding-left: 5%
}


.stars {
    display: inline-block;
    width: 100%
}

.star-input { 
    display: none; 
}

.star-icon {
    float: right;
    padding: 10px;
    font-size: 50px;
}

.star-input:checked ~ .star-icon:before {
    content: '\f005';
    color: #FD4;
}

.star-icon:hover:before, .star-icon:hover ~ .star-icon:before {
    content: '\f005';
    color: #ffea8e;
}

.star-icon:before {
    content: '\f006';
    font-family: FontAwesome;
}

注意:当我尝试使用Bootstrap Grid或在输入周围使用任何div标签时,只会填充一颗星。

我该怎么做才能解决这个问题?

非常感谢。

2 个答案:

答案 0 :(得分:1)

请参阅此处jsfiddle

将div分成5个部分(你有5颗星)

对于另一个问题(星星已经填好)你能举个例子吗?

代码:

.star-icon {
  float: right;
  padding: 10px;
  font-size: 50px;
  box-sizing:border-box;
  width:20%;
}

答案 1 :(得分:0)

你必须在一个div中制作星星块,以便它可以在所有设备中使用。

HTML:

<div class="row">
  <div class="col-md-12 col-sm-12 col-xs-12">
    <div class="stars-div">
      <div class="stars">
        <input class="star-input star-5" id="star-5" type="radio" name="star"/>
        <label class="star-icon star-5" for="star-5"></label>                                   
        <input class="star-input star-4" id="star-4" type="radio" name="star"/>
        <label class="star-icon star-4" for="star-4"></label>
        <input class="star-input star-3" id="star-3" type="radio" name="star"/>
        <label class="star-icon star-3" for="star-3"></label>
        <input class="star-input star-2" id="star-2" type="radio" name="star"/>
        <label class="star-icon star-2" for="star-2"></label>
        <input class="star-input star-1" id="star-1" type="radio" name="star"/>
        <label class="star-icon star-1" for="star-1"></label>
      </div>
    </div>
  </div>
</div>

CSS:

.stars-div {
  padding-top: 9.8%;
  padding-left: 1%
 }


.stars {
  display: inline-block;
  width: 100%
}

.star-input { 
  display: none; 
}

.star-icon {
  float: right;
  padding: 1%;
  font-size: 50px;
}

.star-input:checked ~ .star-icon:before {
  content: '\f005';
  color: #FD4;
}

.star-icon:hover:before, .star-icon:hover ~ .star-icon:before {
     content: '\f005';
     color: #ffea8e;
}

.star-icon:before {
  content: '\f006';
  font-family: FontAwesome;
}