eds1999
eds1999

Reputation: 1058

css hover alternative (automatic)

My CSS has to change using a transition ,and till now i used div:hover for that.

The transition needs to be activated when you click another div, not when you hover over the div that has to move/change .

How can I do that ?

Thanks

Evert

Upvotes: 5

Views: 4367

Answers (1)

Peter Rasmussen
Peter Rasmussen

Reputation: 16922

You cannot handle click events on dom elements with css, you will need to use javascript for this.

You can add a click event to the first div which is fired when you click it. Within the event you select the other div, and make the transition.

Working Demo

You can do this by adding a class with the css transition:

Html:

<div id="clickme">1</div>
<div id="changeMe">2</div>

Javascript:

var el = document.getElementById('clickme');

el.onclick = function() {
    document.getElementById('changeMe').className = "transition";
};

CSS:

.transition{
   /* transition css */
}

Upvotes: 3

Related Questions