Containing image in div container and transition properties not working - css

I'm using Elementor Pro and wanted certain images to zoom within the div container and had a shine on them when hovering, so upon asking for help someone wrote this code for me, but it didn't scale the image. I added the transform property to scale it, but I don't know how to keep it within the container. I also wanted the transition to be smooth so I also added the transition property which doesn't seem to work at all. This is my first time asking asking a question here and I do not have a coding background so I apologize if I say something wrong.
.shine-test::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.5);
content: '';
transition: all 0.6s;
transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, -45deg) translate3d(0, -150%, 0);
}
.shine-test:hover::before {
transform: scale3d(1.9, 1.4, 1) rotate3d(0, 0, 1, -45deg) translate3d(0, 150%, 0);
}
.shine-test:hover {
transition-timing-function: ease-in-out;
transition-duration: .6s;
}
.shine-test:hover {
transform: scale(1.2)
}

You need JavaScript if you want to change the size of the wrapper, because things changed by scale keeps their original 'box'.
Although if you knew the size you were scaling it to you can do something like this:
Box = 40*40
Scale 1.5 = Box width 60*60
.box {
width: 40px;
height: 40px;
}
.box.scaled {
width: 60px;
height: 60px;
}
.box.scaled > .shine-test {
transform: scale(1.5);
}

Related

Why the transitions do not work in my case

I'd like to know why my transition doesn't work in Wordpress while in Codepen it works fine. Hovering on items changes background but it also should do with transition
I am mentally exhausted trying to find out if it's just my stupid mistake or something else in Wordpress could block it.
Here is my codepen
: Codepen
Here is the website I'm applying it to: Wordpress page
change the transition from background to background-image
background-image 350ms cubic-bezier(0.77, 0, 0.175, 1)
.container #picture {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: #f5bf30;
transition: background-image 350ms cubic-bezier(0.77, 0, 0.175, 1);
}
Source: http://css3.bradshawenterprises.com/cfimg/
Edit 1:
Initial background using 1x1px image
.container #picture {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8ut/gPwAHegLlBdE8JgAAAABJRU5ErkJggg==);
transition: background-image 350ms cubic-bezier(0.77, 0, 0.175, 1);
}
the image used in this example is generated with png-pixel
Edit 2:
I had a look at your implementation of my suggested change,
you want to replace transition: background 1350ms cubic-bezier(0.77, 0, 0.175, 1) !important; with transition: background-image 350ms cubic-bezier(0.77, 0, 0.175, 1); for the initial setup .container #picture
it works perfect like that when I test it.
and remove the rules you added to .container #picture.one, .container #picture.two, ... etc
Edit 3:
Side by side example showing the difference between color to image and image to image transition;
.square {
width:150px;
height:150px;
transition: background-image 350ms cubic-bezier(0.77, 0, 0.175, 1);
float: left;
margin-right:50px;
}
.example-1 {
background: #f5bf30;
}
.example-2 {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8ut/gPwAHegLlBdE8JgAAAABJRU5ErkJggg==);
}
.example-1:hover, .example-2:hover{
background-image:url(https://via.placeholder.com/150);
}
<div class="square example-1"></div>
<div class="square example-2"></div>

CSS Safari transition with transform and width not working

.items {
position: relative;
display: block;
background-color: red;
height: 300px;
width: 100px;
transform: translate3d(0, 0, 0);
-webkit-transform: translate3d(0, 0, 0);
transition: all 1s ease;
-webkit-transition: all 1s ease;
}
.items.animation {
width: 50%;
transform: translate3d(50%, 50%, 0);
-webkit-transform: translate3d(50%, 50%, 0);
}
I use transition to animate transform and width in the same time.
It works well in other browsers but not in safari.
When the animation(transition) finished, get the element value correctly. But 'width' and 'transform' doesnt work by transition (for example 1sec).
Safari doesnt calculate the width value by transition in my opinion. Thats why this transfrom translate 50% calculate with the origin value of width...
I wouldnt like to create one more element as much as possible.
Has anyone idea to figure it?
Example is here:
https://codepen.io/jh-ko/pen/xxdbzga
please test and compare in safari and (chrome/firefox etc.)
This is working as of iOS 15.5 as far as I can tell.

Rotate 45-degree element around vertical axis

I've got a series of elements, as shown in the image below:
They are rotated 45 degrees to one side (the content inside -45 degrees, to remain upright).
Now I'd like to rotate each element around a vertical axis, going through the element's center. RotateY doesn't work, as it is at a 45-degree angle.
How would you go about doing this?
The trick is to set this rotation before the 45 degrees rotation:
Notice also that to make the rotation behave really as expect, you need to set it to 0 in the base state
.container {
width: 200px;
height: 200px;
margin: 100px;
border: solid 1px;
transform: rotateY(0deg) rotate(45deg); /* needs Y at 0 deg to behave properly*/
transition: transform 2s;
}
.container:hover {
transform: rotateY(180deg) rotate(45deg); /* notice the order */
}
.inner {
margin: 50px;
transform: rotate(-45deg);
}
<div class="container">
<div class="inner">INNER</div>
</div>
This is how I interpret the question. I'm not very happy with the demo since it needs a lot of structure.
But maybe you can verify the behavior?
Basically I use a wrapper to rotate on the y-axis.
It is key to set the transform origin to the center.
The additional wrapper is used to prevent a flickering on mouse hover.
https://jsfiddle.net/nm59mqky/1/
.tile {
transform: rotateY(0);
transform-origin: center center;
}
.wrapper:hover .tile {
transform: rotateY(180deg);
}
I dont know exactly what your code looks like, but for a simple spinning tile (div) i would try something like this:
#keyframes rotate-vertical {
0% {
transform: rotate3d(0, 1, 0, 0deg);
}
100% {
transform: rotate3d(0, 1, 0, 360deg);
}
}
body {
padding: 20px;
}
.tile {
width: 65px;
height: 65px;
background-color: red;
text-align: center;
transform: rotate3d(0, 0, 1, 45deg);
display: inline-block;
}
.turndiv {
width: 65px;
}
.turndiv:hover {
animation: rotate-vertical 1.1s ease-out;
}
<div class="turndiv">
<div class="tile">
</div>
</div>
You could just do it with transform: rotate3d(); and without a parent div, but to keep it easy i did it like this.

Make overlay fade out slowly?

I'm currently editing a subreddit on reddit.com and my methods are restricted on CSS only.
I managed to get a overlay effect when you hover over the menu on the left side. It's fading in, but I don't know how to fade it out. Since transition wasn't working I tried another method with an animation.
TL;DR: Overlay fade in: yes - fade out: no :(
Here are some parts of the code I used:
#sr-header-area .drop-choices:hover:before {
content: "";
font-size: 13px;
display: block;
position: fixed !important;
height: 100%;
width: 100%;
margin-left: 300px;
pointer-events: none;
z-index: 700 !important;
animation: fade 0.5s ease;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;}
#keyframes fade {
0% {background-color: rgba(0, 0, 0, 0);}
100% {background-color: rgba(0, 0, 0, 0.4);}}
Maybe someone can help me out here.
You should be able to achieve this effect with transitions and that would be the way I'd personally recommend. Heres a quick implementation: https://jsfiddle.net/z1c8bvcd/1/
The main thing to remember is that you need to define the CSS properties that the div will return to once the hover state is no longer in effect, not just what they look like when hovered otherwise the :before pseudo element will be removed from the DOM.
#foo:before {
content: "";
background: rgba(255, 255, 255, 0);
transition: background 0.5s, margin-left 0.5s;
width: 100%;
height: 100%;
position: fixed!important;
margin-left: 50px;
}
#foo:hover:before {
background: rgba(0, 0, 0, 0.3);
margin-left: 300px;
}
I think you can also achieve a similar effect using keyframes, but I think the animation would run once when the page loads and then whenever the div is hovered.

rotateY() vs matrix3d transitions in Edge

I've come across a strange problem with the way Edge (and IE 11) handles my matrix3d transform. The page I'm working on has elements that already have an arbitrary transform applied to them (due to a plugin being used), however thanks to my manager I now need to apply a 180 degree rotation around the Y axis on top of this. Because of this, I could not simply use the rotateY() function as it replaced the old transform and moved the element, so I figured I'd need to use matrices. This works fine in Chrome and Firefox, but Edge doesn't seem to handle matrix3d in the same way.
Here's an example of using rotateY: http://codepen.io/anon/pen/wGqapy
(HTML)
<body>
<div class="flip-container">
<div class="front">
Test
</div>
</div>
</body>
(CSS)
.flip-container,
.front {
width: 320px;
height: 480px;
}
.front {
transition: 0.6s;
position: absolute;
top: 0;
left: 0;
z-index: 2;
background-color: green;
}
.flip-container:hover .front
{
transform: rotateY(180deg);
}
When you mouse over the element, it rotates around the Y axis in 3D space. And here's an example of using matrix3d, using the same matrix shown in the "computed CSS" tab in Edge: http://codepen.io/anon/pen/QNMbmV
(HTML)
<body>
<div class="flip-container">
<div class="front">
Test
</div>
</div>
</body>
(CSS)
.flip-container,
.front {
width: 320px;
height: 480px;
}
.front {
transition: 0.6s;
position: absolute;
top: 0;
left: 0;
z-index: 2;
background-color: green;
}
.flip-container:hover .front
{
transform: matrix3d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
}
This, however, seems to spin around more than one axis. This does not occur in Firefox or Chrome. Am I supposed to use some magical vendor-specific CSS? I've been unsuccessful in searching SO or Google, so I hope someone has some insight!
Thanks in advance.
Matrices are very good for calculus, and for setting the transforms in an universal way. But aren't so good when you are transitioning from one state to the other.
a simple animation as
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
is impossible to set with matrices
Also, take into account that even using matrices, you can chain them with others transforms.
All that said, let's see an example of your rotation working on a previously transformed element
.flip-container,
.front {
width: 320px;
height: 480px;
}
.front {
transition: 0.6s;
position: absolute;
top: 0;
left: 0;
z-index: 2;
background-color: green;
/* transform: rotate(10deg); is equivalent to matrix(0.984808, 0.173648, -0.173648, 0.984808, 0, 0) */
transform: matrix(0.984808, 0.173648, -0.173648, 0.984808, 0, 0) rotateY(0deg);
}
.flip-container:hover .front {
transform: matrix(0.984808, 0.173648, -0.173648, 0.984808, 0, 0) rotateY(180deg);
}
<div class="flip-container">
<div class="front">
Test
</div>
</div>

Resources