2016-07-01 146 views
0

晚安。CSS星級評分

大家好,我有一個問題:我的頁面中有一個單選按鈕星級分級小部件,此時星星彼此接近,我需要將它們分開(填充div的witdh)。

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; 
} 

注:當我嘗試使用引導程序圖標或使用任何div標籤周圍的輸入只有一個星將被填充。

我能做些什麼來解決這個問題?

非常感謝。

回答

1

看到這裏jsfiddle

只是劃分成DIV 5段(你有5顆星)

對於其他問題(與明星填寫)你能不能給我一個例子嗎?

代碼:

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

非常感謝你,它的工作。 PD:與填充的問題是,如果我使用這個例如

,我不會在我點擊的那個之前填滿星星,但是隨着你的幫助,它正在工作,因爲我需要 –

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; 
}