CSS animation rotation issue - css

I have an animated infinite auto-scrolling carrousel. The tiles of the carrousel ares tilted to transform:rotateX(45deg) but they revert to 0deg because the animation for auto-scrolling has its own transform:. Since the animation is a loop I want the tiles to stay at a fixed rotation so there is no stutter through each loop.
.slider {
background: none;
height: 600px;
margin: auto;
overflow:hidden;
position: relative;
display: flex;
align-items: center;
width: 100%;
}
.slider::before,
.slider::after {
content: "";
height: 100px;
position: absolute;
width: 200px;
z-index: 2;
}
.slide-track {
animation: scroll 5s linear infinite;
display: flex;
width: calc(300px * 14);
perspective: 9000px;
}
#keyframes scroll {
0% { transform: translateX(0); }
100% { transform: translateX(calc(-300px * 7))}
}
.slide {
width: 300px;
height: 500px;
background-color: #17141d;
margin-left: 30px;
transform: rotateX(45deg) scale(0.8);
border-radius: 10px;
box-shadow: -1rem 0 3rem #000;
display: flex;
justify-content: center;
overflow: hidden;
flex-direction: column;
align-items: center;
}
<div class="slider">
<div class="slide-track">
<div class="slide" ></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
<div class="slide"></div>
</div>
</div>

The transform property accepts multiple values simultaneously. In your case, change the keyframes declaration to this:
#keyframes scroll {
0% { transform: translateX(0) rotateX(45deg) scale(0.8); }
100% { transform: translateX(calc(-300px * 7)) rotateX(45deg) scale(0.8); }
}

Related

Avoid blurring on a child item when hovering a blurred div element / Bootstrap5.2

Pls I would need help to avoid having a blur effect on my child element "text-block" when the mouse is hovering the card element. The card element should completely have a blur effect when hovering with the mouse & display the text block over it.
I tried a lot of options that don't work throught the proposed solutions by the community. Thks a lot.
<div class="container">
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<div class="col">
<div class="card shadow-sm">
<div class="container my-2">
<img src="./images/mnemba_view.JPG" class="w-100 w-sm-120 preview"/>
<div class="text-block">Click to read more</div>
</div> `
.card {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.preview {
position: relative;
}
.text-block {
position: absolute;
opacity: 0;
z-index: 1;
bottom: 0;
top: 50%;
left: 50%;
block-size: 50px;
inline-size: 200px;
padding: 10px 10px;
background-color: rgb(189, 113, 20);
color: white;
border-radius: 10px;
}
.card:hover .text-block{
opacity: 1;
transition: opacity 0.5s ease-in-out;
}
.card:not(hover) .text-block {
transition: 0.4s;
}
.card:hover {
filter: blur(2px);
cursor: pointer;
}
I eventually found the solution.
Here's the solution:
.text-block {
position: absolute;
opacity: 0;
bottom: 0;
top: 50%;
left: 50%;
block-size: 50px;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
inline-size: 200px;
background-color: rgb(189, 113, 20);
color: white;
border-radius: 10px;
pointer-events: none;
text-align: center;
}
<div class="album py-5">
<div class="container">
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<div class="col">
<div class="card shadow-sm">
<div class="card-header fw-bold" style="background-color:#b76800a9">Africa</div>
<div class="preview">
<img src="./images/mnemba_view.JPG" alt="Ile de Mnemba" class="w-100 h-sm-200 w-sm-120 align-item-center justify-content-center"/>
<button class="text-block">Click to read more</button>
</div>

css overlay: how do I maintain "relative" position on a "fixed" element?

I have a simple css/js animation that I have styled with 'position: fixed' attribute so that it overlays other elements on the page.
However, I still want the animation to position itself relative to other elements and while this appears to work OK on a full-width page, it goes awry on mobile layouts.
Here's a quick example: https://codepen.io/Megistus/pen/poLGbyL
body{
background-color: yellow;
}
.body-sw {
background-color: none;
height: 20vh;
display: block;
//align-items: center;
justify-content: center;
position: fixed;
top: 3%;
left: 0;
right: 0;
bottom: 0;
}
.sound-wave {
height: 20vh;
display: flex;
align-items: center;
//justify-content: center;
position: absolute;
top: 3%;
left: 0;
right: 0;
bottom: 0;
}
.body-sw .bar {
animation-name: wave-lg;
animation-iteration-count: 3;
animation-timing-function: ease-in-out;
animation-direction: alternate;
background: #006565;
margin: 0 1.5px;
height: 10px;
width: 1px;
}
.body-sw .bar:nth-child(-n+7), .body-sw .bar:nth-last-child(-n+7) {
animation-name: wave-md;
}
.body-sw .bar:nth-child(-n+3), .body-sw .bar:nth-last-child(-n+3) {
animation-name: wave-sm;
}
#keyframes wave-sm {
0% {
opacity: 0.35;
height: 10px;
}
100% {
opacity: 1;
height: 25px;
}
}
#keyframes wave-md {
0% {
opacity: 0.35;
height: 15px;
}
100% {
opacity: 1;
height: 50px;
}
}
#keyframes wave-lg {
0% {
opacity: 0.35;
height: 15px;
}
100% {
opacity: 1;
height: 70px;
}
}
(excuse the messy css, there's a lot of unnecessary guff in there!)
As you can see, I'm hoping got the animation to maintain its position between the "LOGO" div above and the "content" div below, but for the expanded "bars" in the animation to overlay the elements above and below it when the animation plays (on page load).
Is there a way to do this?
You actually do not want to use position: fixed;. This will forced the element to a fixed position on the page.
Instead, you can set position: absolute;, which will give you what seems to be the same result, however if you modify your HTML a little, you can get the animation to stay with the logo.
You need to place the animation elements inside of a container that holds both the logo and the animation. Then if you set this parent container to position: relative; now your animation elements will stay with the logo and the position: absolute; you set will allow the animation to overlay the logo still.
window.addEventListener("load", () => {
const bar = document.querySelectorAll(".bar");
for (let i = 0; i < bar.length; i++) {
bar.forEach((item, j) => {
// Random move
item.style.animationDuration = `${Math.random() * (0.7 - 0.2) + 0.2}s`; // Change the numbers for speed / ( max - min ) + min / ex. ( 0.5 - 0.1 ) + 0.1
});
}
});
body{
background-color: yellow;
}
.logo { position: relative; }
.body-sw {
background-color: none;
height: 20vh;
display: block;
//align-items: center;
justify-content: center;
position: absolute;
top: -.5em;
left: -.5em;
right: 0;
bottom: 0;
}
.sound-wave {
height: 20vh;
display: flex;
align-items: center;
//justify-content: center;
}
.body-sw .bar {
animation-name: wave-lg;
animation-iteration-count: 3;
animation-timing-function: ease-in-out;
animation-direction: alternate;
background: #006565;
margin: 0 1.5px;
height: 10px;
width: 1px;
}
.body-sw .bar:nth-child(-n+7), .body-sw .bar:nth-last-child(-n+7) {
animation-name: wave-md;
}
.body-sw .bar:nth-child(-n+3), .body-sw .bar:nth-last-child(-n+3) {
animation-name: wave-sm;
}
#keyframes wave-sm {
0% {
opacity: 0.35;
height: 10px;
}
100% {
opacity: 1;
height: 25px;
}
}
#keyframes wave-md {
0% {
opacity: 0.35;
height: 15px;
}
100% {
opacity: 1;
height: 50px;
}
}
#keyframes wave-lg {
0% {
opacity: 0.35;
height: 15px;
}
100% {
opacity: 1;
height: 70px;
}
}
<br>
<br>
<br>
<div class="logo">
<h1>LOGO</h1>
<div class="body-sw">
<div class='sound-wave'>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
<div class='bar'></div>
</div>
</div>
</div>
<div>
<h1>Content....</h1>
</div>

How to have 3 #keyframes fill's on the same page?

I am trying to get three keyframes to work independently from each other
I have added some HTML and CSS on a friends codepen account to show you.
https://codepen.io/williamharvey/pen/JjJjRdz
I have three circular dials that have the following.
.circle-wrap .circle .fill {
animation: fill ease-in-out 3s;
transform: rotate(45deg);
}
#keyframes fill {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(45deg);
}
}
But I want the second dial to be 65deg
.circle-wrap .circle .fill {
animation: fill ease-in-out 3s;
transform: rotate(65deg);
}
#keyframes fill {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(65deg);
}
}
and the third 95deg
.circle-wrap .circle .fill {
animation: fill ease-in-out 3s;
transform: rotate(95deg);
}
#keyframes fill {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(95deg);
}
}
Is this even possible?
Thanks in advance.
short answser: Yes.
You can use the forwards (keyword) to freeze your animation on its ending value, and CSS var() to apply specific values from different elements but from a single rule :
example from your code :
.circle-wrap {
margin: 50px auto;
width: 240px;
height: 240px;
background: #e5e5e5;
border-radius: 50%;
transform: rotate(-125deg);
}
.circle-wrap .circle .mask,
.circle-wrap .circle .fill {
width: 240px;
height: 240px;
position: absolute;
border-radius: 50%;
}
.circle-wrap .circle .mask {
clip: rect(0px, 240px, 240px, 120px);
}
.circle-wrap .circle .mask .fill {
clip: rect(0px, 120px, 240px, 0px);
background-color: #ffe100;
}
.circle-wrap .circle .mask.full,
.circle-wrap .circle .fill {
animation: fill ease-in-out 3s forwards;
}
#keyframes fill {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate( var(--rt));
}
}
.circle-wrap .inside-circle {
width: 185px;
height: 185px;
border-radius: 50%;
background: #fff;
line-height: 185px;
text-align: center;
top: 28px;
left: 28px;
z-index: 100;
font-weight: 700;
font-size: 6.5rem;
letter-spacing: -4px;
transform: rotate(114deg);
font-style: italic;
font-family: brandon-grotesque;
padding: 0;
position: relative;
}
.circle-wrap .inside-circle span {
font-size: 2.5rem;
letter-spacing: 0;
}
.circle-wrap .inside-circle .cone {
width: 0;
height: 0;
border-left: 175px solid transparent;
border-right: 175px solid transparent;
border-top: 125px solid white;
border-radius: 50%;
transform: rotate(192deg);
position: absolute;
bottom: -33px;
left: -96px;
z-index: -1;
}
.circle-wrap .inside-circle .cone .dial-speeds {
transform: rotate(179deg);
position: relative;
z-index: 1;
font-weight: 400;
font-style: normal;
}
.circle-wrap .inside-circle .cone .dial-speeds .left {
position: absolute;
bottom: -78px;
width: 18px;
height: 20px;
left: -50px;
}
.circle-wrap .inside-circle .cone .dial-speeds .right {
position: absolute;
bottom: -78px;
width: 18px;
height: 20px;
right: -50px;
}
.circle-wrap .inside-circle .cone .dial-speeds .right span {
right: -16px;
top: -58px;
position: absolute;
font-size: 15px;
}
.circle-wrap .inside-circle .cone .dial-speeds .left span {
left: -16px;
top: -58px;
position: absolute;
font-size: 15px;
}
<div class="grid gap-4 grid-cols-3 text-left pt-24">
<div class="circle-wrap">
<div class="circle">
<div class="mask full">
<div class="fill fill"></div>
</div>
<div class="mask half">
<div class="fill fill" style="--rt:45deg"></div>
</div>
<div class="inside-circle">
300<span></span>
<div class="cone">
<div class="dial-speeds">
<div class="left">
<img src="">
<span>300</span>
</div>
<div class="right">
<img src="">
<span>100</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="circle-wrap">
<div class="circle">
<div class="mask full">
<div class="fill"></div>
</div>
<div class="mask half">
<div class="fill" style="--rt:60deg"></div>
</div>
<div class="inside-circle">
500<span></span>
<div class="cone">
<div class="dial-speeds">
<div class="left">
<img src="">
<span>500</span>
</div>
<div class="right">
<img src="">
<span>200</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="circle-wrap">
<div class="circle">
<div class="mask full">
<div class="fill" style="--rt:95deg"></div>
</div>
<div class="mask half">
<div class="fill"></div>
</div>
<div class="inside-circle">
900<span></span>
<div class="cone">
<div class="dial-speeds">
<div class="left">
<img src="">
<span>900</span>
</div>
<div class="right">
<img src="">
<span>300</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Ressources :
https://developer.mozilla.org/en-US/docs/Web/CSS/animation-fill-mode look at forwards
https://developer.mozilla.org/en-US/docs/Web/CSS/var()

When animation is done, how can we smooth out the transition

I am able to achieve smooth in and out effect using transform and transition. I was experimenting with animation but could not achieve smooth out effect.
The first example below works. Note that when you hover, the card will move. And when you no longer hover, the cards to the right will close in slowly.
The second example is the one I'm trying to improve. How can you make the cards close in slowly when using animation? Thanks in advance.
EXAMPLE 1
.container {
display: flex;
margin-top: 100px;
justify-content: center;
}
.card {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
transition: 1s;
}
.card:not(:first-child) {
margin-left: -150px;
}
.card:hover {
transform: translateY(-20px);
}
.card:not(:last-child):hover ~ .card {
transform: translateX(170px);
}
<div class="container">
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
<div class="card">
CARD
</div>
</div>
EXAMPLE 2
.container2 {
display: flex;
justify-content: center;
margin-top: 200px;
}
.tile {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
}
.tile:not(:first-child) {
margin-left: -150px;
}
.tile:not(:last-child):hover ~ .tile {
animation: slide 0.8s linear forwards;
}
#keyframes slide {
0% {
transform: translateX(0px);
}
100% {
transform: translateX(170px);
}
}
.tile:hover {
animation: float 0.8s forwards;
}
#keyframes float {
0% {
transform: translateY(0px);
}
100% {
transform: translateY(-15px);
}
}
<div class="container container2">
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
<div class="tile">
CARD
</div>
</div>
hi in the tile class you should add an animation like this:
.tile {
height: 200px;
width: 200px;
background-color: antiquewhite;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px 15px 1px;
display: flex;
justify-content: center;
align-items: center;
animation-duration: 0.8s;}

css 3d rotate example different size in safari than chrome

I found an example of a 3d cube rotation hover effect that works great except for one thing. When I view it in chrome it's normal sized, and when I view it in safari it's double sized.
I really have no idea why this is happening since I don't see any zoom or webkit-scale happening, any thoughts on this?
http://jsfiddle.net/QMQLQ/
HTML:
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
<div class='box-scene'>
<div class='box'>
<div class='front face'>
<img src='http://placehold.it/180x180/' alt=''>
</div>
<div class="side face">
<p>This is back</p>
</div>
</div>
</div>
CSS:
.box-scene {
-webkit-perspective: 700;
width: 400px;
height: 200px;
margin: auto;
z-index: 999;
}
.box-scene:hover .box {
-webkit-transform: rotateY(-90deg);
}
.box {
-webkit-transform: scale(1,1);
width: 180px;
height: 180px;
position: relative;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 0.4s ease-out;
-webkit-transform-origin: 90px 90px -90px;
/* float: left; */
margin: 30px auto;
}
.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: visible;
-webkit-transform-origin: 0 0;
}
.front {
-webkit-transform: rotateY(0deg);
z-index: 2;
background: #d9d9d9;
}
.side {
background: #9dcc78;
-webkit-transform: rotateY(90deg);
z-index: 1;
left: 180px;
}

Resources