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;
}
Related
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>
I have a diamond shape in one div with an image in it and there is a div with absolute positioned text. On hover, I want the diamond to spin, but not the text. Is it possible to achieve? I suppose I will have to change the HTML a bit.
Here are my attempts so far:
HTML:
<div class="rel">
<div class="dn-diamond">
<h4> Random text </h4>
<div class="dn-diamond-img">
<img src="../images/someImage.png" alt="">
</div>
</div>
</div>
CSS:
.rel {
position: relative;
display: inline;
}
.rel:hover {
animation: spin 3s infinite linear;
}
#keyframes spin {
from { transform: rotateY(0deg); }
to { transform: rotateY(360deg); }
}
.rel:hover .dn-diamond h4 {
-webkit-animation-name: none !important;
animation-name: none !important;
}
.dn-diamond h4 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
letter-spacing: 0.1em;
text-transform: uppercase;
position: absolute;
top: -20px;
left: 20px;
padding: 10px;
z-index: 10;
background: rgba(0, 0, 0, 0.4);
color: #fff;
}
.dn-diamond-img {
width: 420px;
height: 420px;
}
.dn-diamond-img img {
width: 100%;
height: auto;
-webkit-transform: rotate(45deg) translateX(-95px);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg) translateX(-100px) translateY(45px);
transform-origin: 50% 50%;
overflow: hidden;
}
Thanks for any help!
You refer to it as a diamond, so I assume you want to keep it upright. I think this is what you want: http://jsfiddle.net/t67c7ffq/1/
All I did was change .rel:hover to .dn-diamond-img:hover. This won't spin the h4.
I not sure if you are looking for this:
http://codepen.io/luarmr/pen/qdrvgM
My changes
.rel {
position: relative;
}
.rel:hover img{
animation: spin 3s infinite linear;
}
And as well the animation, because donĀ“t make sense for me the jump
#keyframes spin {
from {
transform: rotate(45deg) translateX(-100px) translateY(45px);
transform-origin: 50% 50%;
}
to {
transform: rotate(405deg) translateX(-100px) translateY(45px);
transform-origin: 50% 50%; }
}
}
Assign an id=myimage to your html <img src="../images/someImage.png" alt="" id="myimage">and then change the css from .rel to #myimage. You only need to spin the image, right?
I am having some trouble with some css. I am trying to create a css flipping effect. With what I have right now, it does not show what I have on the front service of my card. Only the back. So essentially a card flips over 180 degrees, but it doesn't properly change. Could anybody take a look at this for me? I would greatly appreciate it!
This is my html
.flip3D {
width: 240px;
height: 200px;
margin: 10px;
float: left;
}
.flip3D > .front {
position: absolute;
-webkit-transform: perspective(600px) rotateY(0deg);
transform: perspective(600px) rotateY(0deg);
background: black;
width: 240px;
height: 200px;
border-radius: 7px;
-webkit-backface-visiblity: hidden;
backface-visiblity: hidden;
transition: -webkit-transform .5s linear 0s;
transition: transform .5s linear 0s;
}
.flip3D > .back {
position: absolute;
-webkit-transform: perspective(600px) rotateY(180deg);
transform: perspective(600px) rotateY(180deg);
background: blue;
width: 240px;
height: 200px;
border-radius: 7px;
-webkit-backface-visiblity: hidden;
backface-visiblity: hidden;
transition: -webkit-transform .5s linear 0s;
transition: transform .5s linear 0s;
}
.flip3D:hover > .front {
-webkit-transform: perspective(600px) rotateY(-180deg);
transform: perspective(600px) rotateY(-180deg);
}
.flip3D:hover > .back {
-webkit-transform: perspective(600px) rotateY(0deg);
transform: perspective(600px) rotateY(0deg);
}
<div class="flip3D">
<div class="front">Box1 - Front</div>
<div class="back">Box1 - Back</div>
</div>
<div class="flip3D">
<div class="front">Box2 - Front</div>
<div class="back">Box2 - Back</div>
</div>
<div class="flip3D">
<div class="front">Box3 - Front</div>
<div class="back">Box3 - Back</div>
</div>
You need this: backface-visibility: hidden;
The backface-visibility property defines whether or not an element should be visible when not facing the screen. http://www.w3schools.com/cssref/css3_pr_backface-visibility.asp
Edit: you need to apply that style to .back
Edit: it's misspelled. Check your spelling
I hope is someone here who can help me find out how should I add the Subtle Hover Effect from this tutorial. I've tried everything, I added the .grid, I have .component imported from css. On my website I have the following HTML
<div class="sixteen columns">
<h4 class="headline">Recent Work</h4>
</div>
<div class="grid">
<figure class="effect-romeo">
<img src="images/5.jpg" alt="img05"/>
<figcaption>
<h2>Wild <span>Romeo</span></h2>
<p>Romeo never knows what he wants. He seemed to be very cross about something.</p>
View more
</figcaption>
</figure>
<figure class="effect-romeo">
<img src="images/5.jpg" alt="img05"/>
<figcaption>
<h2>Wild <span>Romeo</span></h2>
<p>Romeo never knows what he wants. He seemed to be very cross about something.</p>
View more
</figcaption>
</figure>
<figure class="effect-romeo">
<img src="images/5.jpg" alt="img05"/>
<figcaption>
<h2>Wild <span>Romeo</span></h2>
<p>Romeo never knows what he wants. He seemed to be very cross about something.</p>
View more
</figcaption>
</figure>
</div>
<div class="clearfix"></div>
and CSS
figure.effect-romeo {
-webkit-perspective: 1000px;
perspective: 1000px;
}
figure.effect-romeo img {
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(0,0,300px);
transform: translate3d(0,0,300px);
}
figure.effect-romeo:hover img {
opacity: 0.6;
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
figure.effect-romeo figcaption::before,
figure.effect-romeo figcaption::after {
position: absolute;
top: 50%;
left: 50%;
width: 80%;
height: 1px;
background: #fff;
content: '';
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(-50%,-50%,0);
transform: translate3d(-50%,-50%,0);
}
figure.effect-romeo:hover figcaption::before {
opacity: 0.5;
-webkit-transform: translate3d(-50%,-50%,0) rotate(45deg);
transform: translate3d(-50%,-50%,0) rotate(45deg);
}
figure.effect-romeo:hover figcaption::after {
opacity: 0.5;
-webkit-transform: translate3d(-50%,-50%,0) rotate(-45deg);
transform: translate3d(-50%,-50%,0) rotate(-45deg);
}
figure.effect-romeo h2,
figure.effect-romeo p {
position: absolute;
top: 50%;
left: 0;
width: 100%;
-webkit-transition: -webkit-transform 0.35s;
transition: transform 0.35s;
}
figure.effect-romeo h2 {
-webkit-transform: translate3d(0,-50%,0) translate3d(0,-150%,0);
transform: translate3d(0,-50%,0) translate3d(0,-150%,0);
}
figure.effect-romeo p {
padding: 0.25em 2em;
-webkit-transform: translate3d(0,-50%,0) translate3d(0,150%,0);
transform: translate3d(0,-50%,0) translate3d(0,150%,0);
}
figure.effect-romeo:hover h2 {
-webkit-transform: translate3d(0,-50%,0) translate3d(0,-100%,0);
transform: translate3d(0,-50%,0) translate3d(0,-100%,0);
}
figure.effect-romeo:hover p {
-webkit-transform: translate3d(0,-50%,0) translate3d(0,100%,0);
transform: translate3d(0,-50%,0) translate3d(0,100%,0);
}
But the hover effect are strange, it works bad. The images are just 50 % from the original img presented on tutorial.
Hope someone can told me what I should add or remove.
Your answers would be highly appreciated.
Thank you.
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
}