I have been trying to create a 3D looking card-flip type of animation for a project I've been working on. Unfortunately my animation doesn't look entirely 3D.
I've been using this guide. In the first example the person managed to make it look like the windows background was flipping. However when I tried to use the same code on JSFiddle the result was not the same as his.
His demo code made the effect below. When the card is being flipped it causes one side to get smaller giving the impression of perspective:
On my JSFiddle using his code (except a different background), the sides appear to stay the same size the entire time:
Can someone explain to me what I have missed, or how to get the same perspective effect he had on his website? Thanks in advance.
His HTML code:
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="/images/Windows%20Logo.jpg"/>
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
His CSS code:
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#f1_container {
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.face.back {
display: block;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
See where he says he's stripped the vendor prefixes out of his CSS to keep things clean? I'm betting that's your problem. Some of those CSS properties aren't fully standard, but are implemented in different browsers with different vendor prefixes. I'm not actually sure which ones, but Google can help with that.
Edit: Hmm. Well, the CSS is the culprit anyway, but I don't actually see a lot of vendor prefixes. I pulled his actual CSS off of the page, and pasted it in place of the "clean" CSS you used, which makes the fiddle work. His real CSS is:
#f1_container {
height: 281px;
margin: 10px auto;
position: relative;
width: 450px;
z-index: 1;
}
#f1_container {
perspective: 1000px;
}
#f1_card {
height: 100%;
transform-style: preserve-3d;
transition: all 1s linear 0s;
width: 100%;
}
#f1_container:hover #f1_card, #f1_container.hover_effect #f1_card {
box-shadow: -5px 5px 5px #AAAAAA;
transform: rotateY(180deg);
}
.face {
backface-visibility: hidden;
height: 100%;
position: absolute;
width: 100%;
}
.face.back {
-moz-box-sizing: border-box;
background-color: #AAAAAA;
color: #FFFFFF;
display: block;
padding: 10px;
text-align: center;
transform: rotateY(180deg);
}
They had some CSS incorrect...in the example, he had class .back.face, which should have been .face.back (not why it wasn't working, as pointed out. Just cleaned it up). Other issues were the culprit as other posters pointed out. I've created a new jsFiddle. I'd go the jQuery flip plug-in over this though, as IE will have a hard time rendering such effect.
http://jsfiddle.net/JJrHD/1/
Related
Here is a link to a demo
I'm not sure what I'm missing, I've done this before a few times but It's been a day of fighting this particular CSS. I want the image to enlarge, but stay within the dimensions, so a zoom effect versus any enlargement. I've attempted to move the overflow:hidden into other parent or children, but it doesn't have an effect. I've played around with the display settings as well.
Any advice? The JSfiddle link is above, and the code below. Thanks for taking a look!
#purple-square {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/purple_card.png");
border-radius: 10px;
}
#migraine-dentistry {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/migraine_dentistry_card.png");
border-radius: 10px;
}
/* need position: relative in shell otherwisee the elements disappear */
#shell {
margin: auto;
width: 355px;
height: 255px;
position: relative;
transform-origin: center;
transition: 0.3s ease-in-out;
}
#shell:hover {
transform: scale(1.2);
}
#container {
width: 100%;
overflow: hidden;
display: inline-block;
transition: 0.3s;
margin: 0 auto;
}
#container div {
position: absolute;
left: 0;
transition: 0.3s ease-in-out;
}
#container:hover {
transition: ease-in-out 0.3s;
}
#container div.bottom:hover {
opacity: 0;
}
and here is the HTML setup:
<body>
<div id="shell">
<div id="container">
<div id='purple-square' class="top"></div>
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
Full working code snipped below my steps
remove unnecessary elements Removed purple square, because it's never seen in wanted animation.
Removed the part the full #container div.bottom:hover part.
Removed every style that begins with #shell in the css and later trigger the animation on #container:hover.
main issue Add an #migraine-dentistry after the #container:hover animation, so if someone hovers the container it effects the #migraine-dentistry element. (#container:hover #mi.. {trans..})
In this (#container:hov..) element remove everything and
insert transform: scale(1.2);
because we just want to scale if user is hovering.
Remove whole #container div {..} style element, because we will directly add these styles to the #migraine-dentistry element.
In #container define px values for
> width: 355px; and height: 255px;
just because we not use the #shell element anymore. Also
> set position: relative; and z-index: 2;
that the #migrain.. element is inside his parent. And
> set border-radius: 15px;
for styling. Finally
>remove the display and transition values
because they are simply not needed.
last In #migraine-de.. styles
>set width: 100%; and height: 100%;
to fit div to parent.
> remove border-radius tag
because it's set by the #container
> add transition: 0.3s ease-in-out;
to transition like you wanted.
#container {
border-radius: 15px;
width: 355px;
height: 255px;
overflow: hidden;
z-index: 2;
position: relative;
}
#container:hover #migraine-dentistry {
transform: scale(1.2);
}
#migraine-dentistry {
width: 100%;
height: 100%;
transition: 0.3s ease-in-out;
background-image: url('https://images.unsplash.com/flagged/photo-1563248101-a975e9a18cc6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80');
}
<body>
<div id="shell">
<div id="container">
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
I know these long nights where you just can't get it done.
#logo {
position: fixed;
top: 85%;
left: 40%;
height: 104px;
width: 90px;
border: solid 3px black;
border-left: 0px;
opacity: 1;
transform: scale(.9) translate(-50%, -50%);
padding: 2px;
transition: all 1s ease;
box-sizing: border-box;
}
#logo::before {
z-index: 100;
content: "Brand";
line-height: 91px;
font-size: .9rem;
text-align: center;
color: white;
position: fixed;
height: 91px;
width: 91px;
left: -8px;
top: 4px;
background: black;
}
/*for demo only*/body {height:400px;}
<div id="logo"></div>
div#logo is not fixed on scroll... why ??
I've written this code on mobile and haven't tried it on desktop yet. So I'm not sure if it's a mobile only issue. I've probably done something silly here
I also checked it and it's working fine.
Could you post the whole css and html so We can better look at it? Cheers
When I run this code it all seems to be working fine.
You could try adding !important to the position of the logo to see if it works (position: fixed !important;). This might work if the CSS is being overridden by another line of code.
If that does not work you need to give us a bit more information about the browser you are using and update the question with the rest of the code. Thanks!
As you can in my snippet when you run, I have a box and underneath that I have a sort of shadow which slow gets bigger if I hover over the box.
.container{
min-height: 400px;
overflow: auto;
clear: both;
background: red;
}
.content {
max-width: 100%;
width: 441px;
float: left;
text-align: center;
position: relative;
z-index: 2;
}
.content:after {
content: '';
position: absolute;
bottom: -10px;
left: 7px;
right: 0;
margin: 0 auto;
width: 228px;
height: 48px;
border-radius: 50%;
background: #000;
opacity: 0.5;
-webkit-filter: blur(25px);
-o-filter: blur(25px);
-webkit-transform: scale(1, 0.3);
-o-transform: scale(1, 0.3);
}
.content:hover:after {
width: 350px;
height: 80px;
transition: all .8s;
-webkit-transition: all .8s;
-o-transition: all .8s;
-moz-transition: all .8s;
}
<div class="container">
<div class="content">
<h3>Find Your</h3>
<div class="main_content">
<h3>Nearest</h3>
<p>Fryking</p>
</div>
</div>
</div>
How can I make this work on all browsers?
At the moment I only see it on chrome and firefox. When I go to IE and Safari my code does not work.
This is how it looks on chrome:
And here how it looks on safari and IE:
Hope you can help
On the MDN website it says that IE currently has no support for filter CSS property and unluckily I can't see a way to fix this.
MDN css filter
However there are 2 alternatives
Use a picture with transparency (like .png) of a circle gradient. You would need to create it in some kind of software like Adobe Photoshop or find online.
Then you could use it as a background-image in your CSS.
Use the radial-gradient for the background in CSS. (There are lots of websites for generating it)
Should work for:
background: radial-gradient(rgba(0,0,0,1), rgba(0,0,0,0))
(Requires -o- -moz- -webkit- for support in different browsers)
Finally set backgroud-size: 100% 100%
I have an image gallery with a hover effect. once the user hovers over the image it uses a css transform.
transform: scale(1.1);
The image looks like this without the hover effect.
and with the effect it looks like this.
As you can see it does zoom in nicely but somehow the text disapears in the background. I tried using z-index but this has no effect. How do I keep the text in the front?
Here is a jsfiddle : https://jsfiddle.net/xk2us9q8/
z-index requires a positioning value other than static to take effect.
Just add position:relative to the text.
.container {
width: 350px;
height: 350px;
padding: 0px;
margin: 0px;
overflow: hidden;
}
p {
color: white;
width: 350px;
text-align: center;
font-size: 28px;
z-index: 100;
margin-top: -90px;
position: relative;
}
.dnnmedia_image {
width: 350px;
height: 350px;
transition: all .2s ease-in-out;
overflow: hidden;
object-fit: cover;
}
.dnnmedia_image:hover {
transform: scale(1.1);
}
<div class="container">
<img src="https://dummyimage.com/350x350/000/fff" class="dnnmedia_image" />
</div>
<p>
Random text
</p>
i m flipping an image through CSS and its wirking in mozila.but in all other browsers its not working.i m unable to know what i m missing here.
Here is my code for image:
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="http://placehold.it/300x300"/>
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
and Here is my CSS:
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#f1_container {
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.face.back {
display: block;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
</style>
You are using bleeding edge CSS properties.
transform, for example, only works unprefixed in IE 10, Firefox and Opera.
You can get support in webkit based browsers by duplicating the property with a -webkit- prefix (since the implementation is still considered experimental in that engine).
See also: can I use