两颗星星实现的星星点击评分效果实例页面
2016-05-24 16:08
351 查看
本文转载 http://www.zhangxinxu.com/study/201308/hello-star.html
css部分
/* 星星点灯照亮我的家门 */
.star_bg {
width: 120px; height: 20px;
background: url(star.png) repeat-x;
position: relative;
overflow: hidden;
}
.star {
height: 100%; width: 24px;
line-height: 6em;
position: absolute;
z-index: 3;
}
.star:hover {
background: url(star.png) repeat-x 0 -20px!important;
left: 0; z-index: 2;
}
.star_1 { left: 0; }
.star_2 { left: 24px; }
.star_3 { left: 48px; }
.star_4 { left: 72px; }
.star_5 { left: 96px; }
.star_1:hover { width: 24px; }
.star_2:hover { width: 48px; }
.star_3:hover { width: 72px; }
.star_4:hover { width: 96px; }
.star_5:hover { width: 120px; }
label {
display: block; _display:inline;
height: 100%; width: 100%;
cursor: pointer;
}
/* 幕后的英雄,单选按钮 */
.score { position: absolute; clip: rect(0 0 0 0); }
.score:checked + .star {
background: url(star.png) repeat-x 0 -20px;
left: 0; z-index: 1;
}
.score_1:checked ~ .star_1 { width: 24px; }
.score_2:checked ~ .star_2 { width: 48px; }
.score_3:checked ~ .star_3 { width: 72px; }
.score_4:checked ~ .star_4 { width: 96px; }
.score_5:checked ~ .star_5 { width: 120px; }
.star_bg:hover .star { background-image: none; }
/* for IE6-IE8 JS 交互 */
.star_checked {
background: url(star.png) repeat-x 0 -20px;
left: 0; z-index: 1;
}
HTML部分
<div id="starBg" class="star_bg">
<input type="radio" id="starScore1" class="score score_1" value="1" name="score">
<a href="#starScore1" class="star star_1" title="差"><label for="starScore1">差</label></a>
<input type="radio" id="starScore2" class="score score_2" value="2" name="score">
<a href="#starScore2" class="star star_2" title="较差"><label for="starScore2">较差</label></a>
<input type="radio" id="starScore3" class="score score_3" value="3" name="score">
<a href="#starScore3" class="star star_3" title="普通"><label for="starScore3">普通</label></a>
<input type="radio" id="starScore4" class="score score_4" value="4" name="score">
<a href="#starScore4" class="star star_4" title="较好"><label for="starScore4">较好</label></a>
<input type="radio" id="starScore5" class="score score_5" value="5" name="score">
<a href="#5" class="star star_5" title="好"><label for="starScore5">好</label></a>
</div>
css部分
/* 星星点灯照亮我的家门 */
.star_bg {
width: 120px; height: 20px;
background: url(star.png) repeat-x;
position: relative;
overflow: hidden;
}
.star {
height: 100%; width: 24px;
line-height: 6em;
position: absolute;
z-index: 3;
}
.star:hover {
background: url(star.png) repeat-x 0 -20px!important;
left: 0; z-index: 2;
}
.star_1 { left: 0; }
.star_2 { left: 24px; }
.star_3 { left: 48px; }
.star_4 { left: 72px; }
.star_5 { left: 96px; }
.star_1:hover { width: 24px; }
.star_2:hover { width: 48px; }
.star_3:hover { width: 72px; }
.star_4:hover { width: 96px; }
.star_5:hover { width: 120px; }
label {
display: block; _display:inline;
height: 100%; width: 100%;
cursor: pointer;
}
/* 幕后的英雄,单选按钮 */
.score { position: absolute; clip: rect(0 0 0 0); }
.score:checked + .star {
background: url(star.png) repeat-x 0 -20px;
left: 0; z-index: 1;
}
.score_1:checked ~ .star_1 { width: 24px; }
.score_2:checked ~ .star_2 { width: 48px; }
.score_3:checked ~ .star_3 { width: 72px; }
.score_4:checked ~ .star_4 { width: 96px; }
.score_5:checked ~ .star_5 { width: 120px; }
.star_bg:hover .star { background-image: none; }
/* for IE6-IE8 JS 交互 */
.star_checked {
background: url(star.png) repeat-x 0 -20px;
left: 0; z-index: 1;
}
HTML部分
<div id="starBg" class="star_bg">
<input type="radio" id="starScore1" class="score score_1" value="1" name="score">
<a href="#starScore1" class="star star_1" title="差"><label for="starScore1">差</label></a>
<input type="radio" id="starScore2" class="score score_2" value="2" name="score">
<a href="#starScore2" class="star star_2" title="较差"><label for="starScore2">较差</label></a>
<input type="radio" id="starScore3" class="score score_3" value="3" name="score">
<a href="#starScore3" class="star star_3" title="普通"><label for="starScore3">普通</label></a>
<input type="radio" id="starScore4" class="score score_4" value="4" name="score">
<a href="#starScore4" class="star star_4" title="较好"><label for="starScore4">较好</label></a>
<input type="radio" id="starScore5" class="score score_5" value="5" name="score">
<a href="#5" class="star star_5" title="好"><label for="starScore5">好</label></a>
</div>
相关文章推荐
- iOS_远程推送(官方)
- C语言:算术运算符与算术表达式
- CSDN 编辑文章
- Eclipse 批量转换文件编码
- Android universal-image-loader详细解析
- html模板引擎jade的使用
- iOS_本地推送
- PHP-Protobuf的编译
- antd循环输出
- xUtils框架
- 第十三周实践项目2————动物这样叫(2)
- Android阅读器文字分散对齐及TextView中的字分散对齐,首尾缩进
- 第十二周—阅读程序(2)
- Android——View对点击事件的处理
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- Spreadsheet::ParseExcel
- Bio::DB::GenBank, Bio::SeqIO
- sqlalchemy访问sql server,需要安装pymssql模块
- android SQLite数据库的使用
- 3 Ways to Learn Whether a Windows Program is 64-bit or 32-bit