admin管理员组

文章数量:1425758

I have a jquery carousel that is applying a class of 'active' to an image that is in a div. In this same div I also have a span with a class of 'fade' which is applying a css style of opacity: 0; I am wondering if there is a way either with CSS or javascript to change the CSS style of span class to opacity: 1; when the image (which is on the same level of the span tag) has the 'active' class applied to it.

<div> 
     <img src="image1" class="active">
     <span class="fade">
         <p>Text</p>
     </span>
</div>

I have a jquery carousel that is applying a class of 'active' to an image that is in a div. In this same div I also have a span with a class of 'fade' which is applying a css style of opacity: 0; I am wondering if there is a way either with CSS or javascript to change the CSS style of span class to opacity: 1; when the image (which is on the same level of the span tag) has the 'active' class applied to it.

<div> 
     <img src="image1" class="active">
     <span class="fade">
         <p>Text</p>
     </span>
</div>
Share Improve this question asked Dec 30, 2012 at 8:21 Tristan MartinTristan Martin 351 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

In CSS use adjacent sibling selector:

img.active + span.fade {
    /* styles here */
}​

DEMO: http://jsfiddle/QBfPg/

本文标签: javascriptApplying a CSS style to a class based on another class on the same levelStack Overflow