我有:
.sketch_img_thumb_box .title{
opacity: 0.1;
}
.sketch_img_thumb_box:hover .title{
opacity: 1;
}
.sketch_img_thumb_box .artist{
opacity: 0.1;
}
.sketch_img_thumb_box:hover .artist{
opacity: 1;
}
.sketch_img_thumb_box .rating_bar {
opacity: 0.1;
}
.sketch_img_thumb_box:hover .rating_bar {
opacity: 1;
}我把它写成:
.sketch_img_thumb_box .title, .sketch_img_thumb_box .artist, .sketch_img_thumb_box .rating_bar{
opacity: 0.1;
}
.sketch_img_thumb_box:hover .title, .sketch_img_thumb_box:hover .artist, .sketch_img_thumb_box:hover .rating_bar{
opacity: 1;
}我们还能进一步优化吗?
发布于 2011-10-14 14:24:49
像这样写
css:
.sketch_img_thumb_box{
opacity: 0.1;
}
.sketch_img_thumb_box:hover{
opacity: 1;
}html:
<div class="sketch_img_thumb_box">
<div class="title"></div>
<div class="artist"></div>
<div class="rating_bar"></div>
</div>因为如果你给opacity parent,那么children会自动得到不透明度。
检查fiddle http://jsfiddle.net/sandeep/axuxT/4/
如果还有您不想给opacity的其他children,请编写以下代码:
.no_bar{width:50px;height:50px;margin:5px;}
.sketch_img_thumb_box > *{opacity:0.1;display:inline-block;}
.sketch_img_thumb_box:hover > *{opacity:1}
.no_bar{background:black;opacity:1}检查fiddle http://jsfiddle.net/sandeep/RqP6p/
https://stackoverflow.com/questions/7763753
复制相似问题