2

我有:

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

我们可以进一步优化吗?

4

1 回答 1

1

像这样写

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获得不透明度。

检查小提琴http://jsfiddle.net/sandeep/axuxT/4/

&如果还有其他children您不想提供的,请opacity写下:

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

检查小提琴http://jsfiddle.net/sandeep/RqP6p/

于 2011-10-14T06:24:49.060 回答