How to make objects move with CSS? - html

I have two images (objects) set side by side in the middle of the page and I want them to move toward each other as if they are going to collide and stop as they are placed beside each one.
So, for the object at the right side I have written the following code, thinking that the object should move from left to right, but the result is far from what I expect. Is it possible to do it by transition? what I want is that one of the objects start moving from left side and the other start moving from the right and meet at the center as if they want to collide.
.one {
border: 3px solid #73AD21;
position: absolute;
}
.two {
top: 45%;
left: 44%;
}
.left1,
.right2 {
float: left;
}
#axis:hover .move-right {
transform: translate(-350px, 0);
-webkit-transform: translate(-350px, 0);
-o-transform: translate(-350px, 0);
-moz-transform: translate(-350px, 0);
}
.object1 {
position: absolute;
transition: all 2s ease-in;
-webkit-transition: all 2s ease-in;
-moz-transition: all 2s ease-in;
-o-transition: all 2s ease-in;
}
<div id="axis" class="one two">
<img class="object1 left1 move-right" src="http://placehold.it/50x50" />
<img class="object2 right2 move-left" src="http://placehold.it/75x75" />
</div>

I have two images [...] what I want is that one of the objects start moving from left side and the other start moving from the right and meet at the center as if they want to collide.
Is it possible to do it by transition?
Yes it is - if I have understood your question correctly.
An important consideration with CSS transitions is that you should explicitly set the start-state and the end-state, so the browser is clear what it is transitioning between.
So... in the example you post in your question, it's important to state the translateX position for the images when :hover applies, but also when :hover doesn't apply.
That way, the browser can be clear what two translateX co-ordinates it is transitioning between.
Example:
#axis {
border: 3px solid #73AD21;
position: absolute;
top: 45%;
left: 44%;
}
#axis img {
float: left;
transition: all 1s ease-in;
-webkit-transition: all 1s ease-in;
-moz-transition: all 1s ease-in;
-o-transition: all 1s ease-in;
}
#axis .move-left {
transform: translateX(200px);
-webkit-transform: translateX(200px);
-o-transform: translateX(200px);
-moz-transform: translateX(200px);
}
#axis .move-right {
transform: translateX(-200px);
-webkit-transform: translateX(-200px);
-o-transform: translateX(-200px);
-moz-transform: translateX(-200px);
}
#axis:hover .move-left, #axis:hover .move-right {
transform: translateX(0px);
-webkit-transform: translateX(0);
-o-transform: translateX(0);
-moz-transform: translateX(0);
}
p {
font-weight:bold;
}
<p>Hover over the green border box.</p>
<div id="axis">
<img class="move-right" src="http://placehold.it/50x50" />
<img class="move-left" src="http://placehold.it/75x75" />
</div>
Version 2 (move just once when the page loads)
function initialiseAxisImages() {
var axis = document.getElementById('axis');
var axisImages = axis.getElementsByTagName('img');
axisImages[0].classList.remove('move-right');
axisImages[1].classList.remove('move-left');
}
window.addEventListener('load', initialiseAxisImages, false);
#axis {
border: 3px solid #73AD21;
position: absolute;
top: 45%;
left: 44%;
}
#axis img {
float: left;
transition: all 1s ease-in;
-webkit-transition: all 1s ease-in;
-moz-transition: all 1s ease-in;
-o-transition: all 1s ease-in;
}
#axis .move-left {
transform: translateX(200px);
-webkit-transform: translateX(200px);
-o-transform: translateX(200px);
-moz-transform: translateX(200px);
}
#axis .move-right {
transform: translateX(-200px);
-webkit-transform: translateX(-200px);
-o-transform: translateX(-200px);
-moz-transform: translateX(-200px);
}
<div id="axis">
<img class="move-right" src="http://placehold.it/50x50" />
<img class="move-left" src="http://placehold.it/75x75" />
</div>

I'm not strong in javascript, so I generally lean on jQuery.
If I were solving it with jQuery I'd decide when I wanted my animation to start then use this code to animate my element:
$('#axis .move-right').addClass('animate');
Here's an example that adds the class .animate when you click on the #axis element.
//binds an anonymous function to the 'click' event on #axis
$('#axis').on('click',function(){
//adds your 'animation' class that triggers the CSS animation
$('#axis .move-right').addClass('animate');
});
.one {
border: 3px solid #73AD21;
position: absolute;
}
.two {
top: 45%;
left: 44%;
}
.left1,
.right2 {
float: left;
}
#axis .move-right.animate {
transform: translate(-350px, 0);
-webkit-transform: translate(-350px, 0);
-o-transform: translate(-350px, 0);
-moz-transform: translate(-350px, 0);
}
.object1 {
position: absolute;
transition: all 2s ease-in;
-webkit-transition: all 2s ease-in;
-moz-transition: all 2s ease-in;
-o-transition: all 2s ease-in;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="axis" class="one two">
<img class="object1 left1 move-right" src="http://placehold.it/50x50" />
<img class="object2 right2 move-left" src="http://placehold.it/75x75" />
</div>
See this updated fiddle for one of the boxes moving into the middle:
https://jsfiddle.net/fuce0x67/
//binds an anonymous function to the 'click' event on #axis
$('#axis').on('click',function(){
//adds your 'animation' class that triggers the CSS animation
$('#axis .move-right').addClass('animate');
});
.one {
border: 3px solid #73AD21;
position: absolute;
}
.two {
top: 45%;
left: 44%;
}
.left1,
.right2 {
float: left;
}
#axis .move-right { //removed animate class from here. This is now the 'default' (pre-animation) position for this element
transform: translate(-350px, 0);
-webkit-transform: translate(-350px, 0);
-o-transform: translate(-350px, 0);
-moz-transform: translate(-350px, 0);
}
#axis .move-right.animate {//added this block to reset the positions to ~center like I think you want
transform: translate(-70px, 0);
-webkit-transform: translate(-70px, 0);
-o-transform: translate(-70px, 0);
-moz-transform: translate(-70px, 0);
}
.object1 {
position: absolute;
transition: all 2s ease-in;
-webkit-transition: all 2s ease-in;
-moz-transition: all 2s ease-in;
-o-transition: all 2s ease-in;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="axis" class="one two">
<img class="object1 left1 move-right" src="http://placehold.it/50x50" />
<img class="object2 right2 move-left" src="http://placehold.it/75x75" />
</div>
<p>
click on the box in the center to activate animation
</p>

Related

CSS transition: chained transforms start simultaneously

Trying to build an hamburger button with animation using css transitions/transforms. I would like the rotation to start only after the translation of the first and the third span is completed (they should overlap with the middle span). Thus I put the transforms chained in the css like so:
transform: translate(0, -28px) rotate(-45deg);
but it seems not working, rotation starts together with translation. Anyone knows how to fix?
$( window ).load(function() {
$("#hamburger").click(function(){
$(this).toggleClass("open");
});
});
*, *:before, *:after {
box-sizing: border-box;
}
body {
background-color: #333;
}
#hamburger {
margin: 2em;
position: relative;
width: 80px;
height: 60px;
cursor: pointer;
}
#hamburger span {
display: block;
position: absolute;
left: 0;
width: 100%;
height: 4px;
background: #fff;
-webkit-transition: transform .25s linear;
-moz-transition: transform .25s linear;
-o-transition: transform .25s linear;
transition: transform .25s linear;
&:nth-child(2) {
-webkit-transition: width 0s linear .25s;
-moz-transition: width 0s linear .25s;
-o-transition: width 0s linear .25s;
transition: width 0s linear .25s;
}
}
#hamburger span:nth-child(1) {
top: 0;
}
#hamburger span:nth-child(2) {
top: 28px;
}
#hamburger span:nth-child(3) {
bottom: 0;
}
#hamburger.open span:nth-child(1) {
-webkit-transform: translate(0, 28px) rotate(45deg);
-moz-transform: translate(0, 28px) rotate(45deg);
-o-transform: translate(0, 28px) rotate(45deg);
transform: translate(0, 28px) rotate(45deg);
}
#hamburger.open span:nth-child(2) {
width: 0;
}
#hamburger.open span:nth-child(3) {
-webkit-transform: translate(0, -28px) rotate(-45deg);
-moz-transform: translate(0, -28px) rotate(-45deg);
-o-transform: translate(0, -28px) rotate(-45deg);
transform: translate(0, -28px) rotate(-45deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hamburger">
<span></span>
<span></span>
<span></span>
</div>
You could split your transform into two different classes, one with translate() and one with rotate(), and then split up the transitions with .delay(), like so:
$("#hamburger").click(function(){
$(this).toggleClass("translateClass");
$(this).delay(250).toggleClass("rotateClass");
);
Solved following #Kadin Zhang suggestion splitting the animation in two transitions. I've substituted the translate transform with a simple change in the top property because in this way the transform-origin moves with the element (otherwise the origin remains in the previous coordinate system and the rotation will be wrong).
$( window ).load(function() {
var state = false;
$("#hamburger").click(function(){
self = $(this);
if (!state) {
self.addClass("open-translate");
setTimeout(function() {
self.addClass("open-rotate");
state = true;
}, 250);
}
else {
self.removeClass("open-rotate");
setTimeout(function() {
self.removeClass("open-translate");
state = false;
}, 250);
}
});
});
*, *:before, *:after {
box-sizing: border-box;
}
body {
background-color: #333;
}
#hamburger {
margin: 2em;
position: relative;
width: 80px;
height: 60px;
cursor: pointer;
}
#hamburger span {
display: block;
position: absolute;
left: 0;
width: 100%;
height: 4px;
background: #fff;
-webkit-transition: all .25s linear;
-moz-transition: all .25s linear;
-o-transition: all .25s linear;
transition: all .25s linear;
&:nth-child(2) {
-webkit-transition: width 0s linear .25s;
-moz-transition: width 0s linear .25s;
-o-transition: width 0s linear .25s;
transition: width 0s linear .25s;
}
}
#hamburger span:nth-child(1) {
top: 0;
}
#hamburger span:nth-child(2) {
top: 28px;
}
#hamburger span:nth-child(3) {
top: 56px;
}
#hamburger.open-translate span:nth-child(1) {
top: 28px;
}
#hamburger.open-rotate span:nth-child(1) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#hamburger.open-translate span:nth-child(2) {
width: 0;
}
#hamburger.open-translate span:nth-child(3) {
top: 28px;
}
#hamburger.open-rotate span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hamburger">
<span></span>
<span></span>
<span></span>
</div>

CSS overlay effect is disturbing CSS text on image

I need to display a text on the image using CSS. I'm doing that using H2 tag:
<h2 class="post-message">Test</h2>
Here is the code for CSS:
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
But the overlay effect is messing things up and here is the code:
.overlay{
overflow: hidden;
background: #000;
}
.overlay img{
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover img{
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
I don't know how to explain what happens and I uploaded 2 screens:
This screen shows the original image without Mouse hover: https://s22.postimg.org/xrsohlcw1/without_mouse_over.jpg
On the first image you see a gray background that I don't know from where comes
The second image is the mouse over effect: that gray image is rotating according to overlay effect and is displayed at the right corner only :/
https://s22.postimg.org/a13x0ndmp/gra_color_disappears.jpg
A little red arrow will show you what happens on the second image. A help would be great! I tried all possible things that I knew, expert opinion always is the best solution. Thanks in advance!
<div class="post-thumbnail overlay">
<a href="http://example.com/comey-wikileaks/">
<img src="http://example.com/wp-content/uploads/2017/04/comey-825x510.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" width="825" height="510">
</a>
<h2 class="post-message">Test</h2>
</div>
An img has a "replaced content" layout model and basically treated as an inline element, and that includes space at the bottom by default for the bottom part of characters, so there will be a small space between the bottom of an img and the bottom of the img's container. To remove that gap at the bottom, either make the img display: block or use vertical-align: top.
If the image is rotating so far that you see the corner of it in the bottom/right corner, either increase your scale() or don't rotate as much until you can't see that anymore. I don't see it with the code you provided.
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
.overlay {
overflow: hidden;
background: #000;
}
.overlay img {
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover img {
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
img {
vertical-align: top;
}
<div class="post-thumbnail overlay">
<a href="http://example.com/comey-wikileaks/">
<img src="http://kenwheeler.github.io/slick/img/fonz1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" width="825" height="510">
</a>
<h2 class="post-message">Test</h2>
</div>
You could actually put your img together with your <h2> inside a <div> and let the whole <div> rotate....
Here is an example base on what you wrote:
(obvously, there's a few things to readjust, but it's more or less what you want, I guess ^^)
.post-message {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
.overlay{
overflow: hidden;
background: #000;
/*these two lines are new*/
display:inline-block;
position:relative;
}
/*I apply style directly on the "overlay"*/
.overlay /*img*/{
-webkit-transition: -webkit-transform .3s ease-out;
-moz-transition: -moz-transform .3s ease-out;
-o-transition: -o-transform .3s ease-out;
transition: transform .3s ease-out;
}
.overlay:hover /*img*/{
-webkit-transform: scale(1.2) rotate(-5deg);
-moz-transform: scale(1.2) rotate(-5deg);
-o-transform: scale(1.2) rotate(-5deg);
-ms-transform: scale(1.2) rotate(-5deg);
transform: scale(1.2) rotate(-5deg);
opacity: 0.7;
}
<span class="overlay">
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" />
<h2 class="post-message">Test</h2>
</span>

Image moves on hover when apply an opacity and transform

I have applied an effect to the image and when I hover over it it moves very strange, it is a move very small but I don't like it, also the text over the image moves when the mouse is out from the image.
This is my code, as you can see is a very imperceptible, but looks strange.
I also would like to make the images responsive when I change resolution, but I would like to have a height like 150px and make the image centered or crop it to the height.
This is my pen code: http://codepen.io/yunielth/pen/wWRydp
HTML
<div class="picture-block margin-0">
<div class="col-lg-3 col-md-6 sub-box-picture">
<div class="content-inner">
<div class="entry-thumbnail">
<div class="thumbnail"><a title="" href="/cursos/madrid"><img src="http://charitywp.thimpress.com/demo-4/wp-content/uploads/sites/6/2016/03/01_home_01_13-370x270.jpg"" alt="" title=""></a></div>
<a class="ciudades" title="" href="">Product 1</a>See more
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 sub-box-picture">
<div class="content-inner">
<div class="entry-thumbnail">
<div class="thumbnail"><a title="" href=""><img src="http://charitywp.thimpress.com/demo-4/wp-content/uploads/sites/6/2016/03/01_home_01_13-370x270.jpg"" alt="" title=""></a></div>
<a class="ciudades" title="" href="">Product 2</a>See more
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 hidden-xs sub-box-picture">
<div class="content-inner">
<div class="entry-thumbnail">
<div class="thumbnail"><a title="" href=""><img src="http://charitywp.thimpress.com/demo-4/wp-content/uploads/sites/6/2016/03/01_home_01_13-370x270.jpg"" alt="" title=""></a></div>
<a class="ciudades" title="" href="">Product 3</a>See more
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 hidden-xs sub-box-picture">
<div class="content-inner">
<div class="entry-thumbnail">
<div class="thumbnail"><a title="" href=""><img src="http://charitywp.thimpress.com/demo-4/wp-content/uploads/sites/6/2016/03/01_home_01_13-370x270.jpg"" alt="" title=""></a></div>
<a class="ciudades" title="" href="">Product 4</a>See more
</div>
</div>
</div>
</div>
CSS
.ciudades{
color: #ffffff;
display: table-cell;
font-size: 24px;
font-weight: 500;
line-height: 25px;
text-align: center;
text-shadow: 1px 2px #333;
vertical-align: middle;
width: 90%;
}
.sub-box-picture .content-inner {
border: none;
background-color: #FFF;
}
.sub-box-picture .entry-thumbnail {
position: relative;
overflow: hidden;
text-align: center;
}
.sub-box-picture .entry-thumbnail .thumbnail::before {
background: #000 none repeat scroll 0 0;
bottom: 0;
content: "";
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
transition: all 0.3s ease 0s;
z-index: 2;
}
.sub-box-picture .thumbnail {
position: relative;
overflow: hidden;
padding: 0;
}
.sub-box-picture .thumbnail img {
width: 100%;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
-ms-transition: all 1s;
transition: all 1s;
-webkit-transition: all all 1s ease;
-moz-transition: all all 1s ease;
-ms-transition: all all 1s ease;
-o-transition: all all 1s ease;
transition: all all 1s ease;
}
.sub-box-picture .thumbnail {
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
border: none;
}
.sub-box-picture .ciudades {
transform: translate(-50%,-50%) scale(1);
-webkit-transform: translate(-50%,-50%) scale(1);
-moz-transform: translate(-50%,-50%) scale(1);
-ms-transform: translate(-50%,-50%) scale(1);
-o-transform: translate(-50%,-50%) scale(1);
left: 50%;
position: absolute;
top: 50%;
z-index: 3;
}
.thim-button.style3 {
display: none;
}
.sub-box-picture a.ciudades {
color: #ffffff;
text-decoration: none;
}
.sub-box-picture:hover .entry-thumbnail .thumbnail::before {
-moz-opacity: .5;
-khtml-opacity: .5;
-webkit-opacity: .5;
opacity: .5;
-ms-filter: alpha(opacity=50);
filter: alpha(opacity=50);
}
.thim-button.style3 {
display: block;
}
.sub-box-picture:hover .thumbnail img {
transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
.sub-box-picture .thim-button.style3 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%) scale(0);
-webkit-transform: translate(-50%,-50%) scale(0);
-moz-transform: translate(-50%,-50%) scale(0);
-ms-transform: translate(-50%,-50%) scale(0);
-o-transform: translate(-50%,-50%) scale(0);
-webkit-transition: all .5s ease-in-out 0s;
-moz-transition: all .5s ease-in-out 0s;
-o-transition: all .5s ease-in-out 0s;
-ms-transition: all .5s ease-in-out 0s;
transition: all .5s ease-in-out 0s;
-webkit-transition: all .3s ease;
-moz-transition: all .5s ease;
-ms-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
white-space: nowrap;
z-index: 3;
}
.sub-box-picture:hover .thim-button.style3 {
transform: translate(-50%,-50%) scale(1);
-webkit-transform: translate(-50%,-50%) scale(1);
-moz-transform: translate(-50%,-50%) scale(1);
-ms-transform: translate(-50%,-50%) scale(1);
-o-transform: translate(-50%,-50%) scale(1);
}
.sub-box-picture:hover .ciudades {
transform: translate(-50%,-50%) scale(0);
-webkit-transform: translate(-50%,-50%) scale(0);
-moz-transform: translate(-50%,-50%) scale(0);
-ms-transform: translate(-50%,-50%) scale(0);
-o-transform: translate(-50%,-50%) scale(0);
left: 50%;
position: absolute;
top: 50%;
visibility: hidden;
}
.thim-button.style3 {
background-color: #3080B2;
border-color: #3080B2;
color: #fff;
}
.thim-button.style3:hover {
background-color: #3080B2;
border-color: #3080B2;
text-decoration: none;
}
.thim-button {
border: none;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
font-size: 20px;
line-height: 36px;
padding: 0 20px;
display: inline-block;
}

Image transform rotate not rotating

I am trying to get an image of an X I have to rotate 180 degrees when it is being hovered over, however it is just moving up and to the right instead of rotating.
What am I doing wrong that this won't look like it is spinning 180 degrees?
.black {
background: #000;
width: 100%;
height: 400px;
}
.popup-close {
position: absolute;
top: 40px;
right: 40px;
}
#x-close:hover {
-webkit-transform: translate(50%, -50%) rotate(180deg);
transform: translate(50%, -50%) rotate(180deg);
}
<div class="black">
<a class="popup-close" data-popup-close="popup-1" href="#">
<img src="http://optimumwebdesigns.com/icons/delete-cross.png" alt="" height="40px" width="40px" id="x-close">
</a>
</div>
The cross moves up (and to the right) because of the translate transform that you are adding when it is being hovered. I believe you are adding this to center the element and in that case, it is better that it is added to the default state of the element itself.
The rotate is actually happening but you aren't seing it because a 180deg rotate of a cross gives the same output. You can add a transition to see the rotation (or) change the rotation angle.
.black {
background: #000;
width: 100%;
height: 400px;
}
.popup-close {
position: absolute;
top: 40px;
right: 40px;
}
#x-close {
transform: translate(50%, -50%);
transition: transform 1s ease;
}
#x-close:hover {
-webkit-transform: translate(50%, -50%) rotate(180deg);
transform: translate(50%, -50%) rotate(180deg);
}
<div class="black">
<a class="popup-close" data-popup-close="popup-1" href="#">
<img src="http://optimumwebdesigns.com/icons/delete-cross.png" alt="" height="40px" width="40px" id="x-close">
</a>
</div>
Working Demo
add this is css in your code:
#x-close{
-webkit-transition: -webkit-transform .8s ease-in-out;
transition: transform .8s ease-in-out;
-webkit-transform: translate(50%, -50%);
transform: translate(50%, -50%) ;
}
Here is my solution
#-webkit-keyframes spin {
100% { -webkit-transform: rotate(180deg); }
}
#-moz-keyframes spin {
100% { -moz-transform: rotate(180deg); }
}
#keyframes spin {
100% {
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
transform:rotate(180deg);
}
}
https://jsfiddle.net/hk2ums6p/
This should do it :
#x-close:hover {
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
-webkit-transition: transform 0.5s ease;
transition: transform 0.5s ease;
}

Activating more the one transition on mouse hover

In my css I have 3 cogs, I want when I hover one of the cogs, that the other 2 cogs also get activated.
My codes:
CSS
#box_1{
border: 1px solid red;
display: block;
position: relative !important;
width: 200px;
height: 200px;
}
.object1 {
position: absolute !important;
}
.cog1 {
top: 18%;
left: 5%;
}
.object2 {
position: absolute !important;
}
.cog2 {
top: 8%;
left: 54%;
}
.object3 {
position: absolute !important;
}
.cog3 {
top: 60%;
left: 54%;
}
.object1 {
position: absolute;
transition: all 20s ease-in;
-webkit-transition: all 20s ease-in; /** Chrome & Safari **/
-moz-transition: all 20s ease-in; /** Firefox **/
-o-transition: all 20s ease-in; /** Opera **/
}
#axis1:hover .rotate360cw {
transform: rotate(3600deg);
-webkit-transform: rotate(3600deg);
-o-transform: rotate(3600deg);
-moz-transform: rotate(3600deg);
}
.object2 {
position: absolute;
transition: all 2s ease-in-out;
-webkit-transition: all 2s ease-in-out; /** Chrome & Safari **/
-moz-transition: all 2s ease-in-out; /** Firefox **/
-o-transition: all 2s ease-in-out; /** Opera **/
}
#axis2:hover .rotate360cw {
transform: rotate(-360deg);
-webkit-transform: rotate(-360deg);
-o-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
}
.object3 {
position: absolute;
transition: all 2s ease-in-out;
-webkit-transition: all 2s ease-in-out; /** Chrome & Safari **/
-moz-transition: all 2s ease-in-out; /** Firefox **/
-o-transition: all 2s ease-in-out; /** Opera **/
}
#axis3:hover .rotate360cw {
transform: rotate(-360deg);
-webkit-transform: rotate(-360deg);
-o-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
}
HTML
<div id="box_1">
<div id="axis1"><img class="object1 cog1 rotate360cw aligncenter" alt="" src="http://biready.visseninfinland.nl/wp-content/uploads/2014/01/512px-Cog_font_awesome.svg.png" width="128" height="128" /></div>
<div id="axis2"><img class="object2 cog2 rotate360cw aligncenter" alt="" src="http://biready.visseninfinland.nl/wp-content/uploads/2014/01/512px-Cog_font_awesome.svg1-e1390559689165.png" width="64" height="64" /></div>
<div id="axis3"><img class="object3 cog3 rotate360cw aligncenter" alt="" src="http://biready.visseninfinland.nl/wp-content/uploads/2014/01/512px-Cog_font_awesome.svg2-e1390559748608.png" width="64" height="64" /></div>
</div>
Check this at fiddle here.
How can I achieve this?
try adding this to your css
#box_1:hover .rotate360cw {
transform: rotate(-360deg);
-webkit-transform: rotate(-360deg);
-o-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
}
Not 100% thats the result you want.
DEMO
Peace.
Add, for instance:
#axis1:hover ~ div > img {
-webkit-transform: rotate(-360deg) !important;
}
Same can be done also for #axis2:hover ~ div > img. Unfortunately CSS can't ascend so therefore you can't declare a rule which would apply from cog2 to cog1 or from cog3 to cog2/cog1. This could only be solved with JavaScript.
You cannot archive this with siblin selectors, since you cannot ascent in CSS (you cannot affect .cog1 when hovering .cog3).
An idea is to give the container the effect trigger:
#box1:hover img[class*="cog"] {
niceHoverEffect
}