Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Half star with CSS

Tags:

html

css

rating

How can I have the same result (a half star) in IE and Chrome.

In chrome : http://jsfiddle.net/Auqj8/

.star {
    font-size: x-large;
    width: 50px;
    display: inline-block;
    color: gray;
}
.star:last-child {
    margin-right: 0;
}
.star:before {
    content: '\2605';
}
.star.on {
    color: gold;
}
.star.half:after {
        content: '\2605';
        color: gold;
        margin-left: -20px;
        width: 10px;
        position: absolute;
        overflow: hidden;
}

In IE: http://jsfiddle.net/86pqx/

Thank you.

like image 729
zak zak Avatar asked Feb 11 '14 00:02

zak zak


People also ask

How do you show half stars in CSS?

Just set . star width to 24 and . star. half:after margin-left to -24px, width to 12px, and the half-stars will render correctly.


1 Answers

This works in both chrome and IE

.star {
    font-size: x-large;
    width: 50px;
    display: inline-block;
    color: gray;
}
.star:last-child {
    margin-right: 0;
}
.star:before {
    content:'\2605';
}
.star.on {
    color: gold;
}
.star.half:after {
    content:'\2605';
    color: gold;
    position: absolute;
    margin-left: -20px;
    width: 10px;
    overflow: hidden;
}

Chrome: http://jsfiddle.net/Auqj8/1/

IE: http://jsfiddle.net/86pqx/3/

like image 177
aaronmallen Avatar answered Sep 28 '22 06:09

aaronmallen