css transition on one image causes nearby images jitter - css

Why a mouse over transition in one image causing a jitter in nearby images?
The images are large and fits in the div with width:100%.
Observed the issue in chrome.
.post:hover figure img {
transform: scale(1.03);
}
.post img {
transition: all cubic-bezier(.4,0,.2,1) .3s;
transform: scale(1);
}

/* Main Div css start here */
.slide_Wrapper {
display: flex;
}
/* This is for child div */
.slide {
width: 290px;
height: 160px;
overflow: hidden;
background: #000;
margin:10px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
border-radius: 10px;
}
/* This is for child div border */
.slide::after {
content: "";
position: absolute;
width: 90%;
height: 82%;
border: 2px solid #fff;
left: 50%;
top: 50%;
z-index: 2;
transform: translate(-50%,-50%);
}
/* Background images */
.slide img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all cubic-bezier(.4,0,.2,1) .3s;
transform: scale(1);
position: absolute;
}
/* Background images on hover */
.slide:hover img {
transform: scale(1.2);
}
/* Text */
.slide h2{
position: relative;
z-index: 2;
color: #fff;
}
<!-- Here I create a main div and two child div -->
<div class="slide_Wrapper">
<div class="slide">
<img src="https://images.pexels.com/photos/1591447/pexels-photo-1591447.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
<h2>XYZ</h2>
</div>
<div class="slide">
<img src="https://images.pexels.com/photos/1591447/pexels-photo-1591447.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
<h2>ABC</h2>
</div>
</div>

Related

Image is not in center on safari mobile web

I implemented css animation to the image and it works well on explorer or chrome through the pc.
Though, on safari, the image is placed in the left top corner. Since I'm using position: absolute and relative for animation, I can't use display:flex option.
Plus, as you can see from below ss, card size is also not fit as applied in css, and have weird space between card and buttons.
current status on safari
Here is my current code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
img {
vertical-align: middle;
}
.container {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-image: url("../../images/background-forloading.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.flip-card {
width: 100%;
height: 80vh;
perspective: 1600px;
cursor: pointer;
transform: translateY(40px) rotateX(-8deg) rotateY(10deg);
animation: movement 5s infinite;
}
#keyframes movement {
50% {
transform: translateY(-40px) rotateX(8deg) rotateY(-10deg);
}
}
.flip-card div {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
backface-visibility: hidden;
transition: 0.7s;
width: 100vw;
height: 80vh;
}
.flip-card div img {
width: 100vw;
height: 80vh;
object-fit: contain;
}
.front {
filter: drop-shadow(0 0 30px #000);
}
.back {
transform: rotateY(180deg);
}
.flip-card:hover .front {
transform: rotateY(-180deg);
}
.flip-card:hover .back {
transform: rotateY(0);
filter: drop-shadow(0 0 20px rgb(120, 185, 232));
}
<div class="container">
<div class="flip-card">
<div class="front">
<img src="images/귀문관카드뒤.png">
</div>
<div class="back">
<img src="images/인간.png">
</div>
</div>
<div class="flip-card-button text-center">
<button class="enter">Save</button>
<button type="submit" class="enter">Next</button>
</div>
</div>
I'm not sure if it solves your problem, but your code is currently missing the browser prefixes.
-webkit- for Chrome, Safari, Opera, iOS
-moz- Firefox
-ms- Internet Explorer and Edge

Transform: scale() not transforming from center

When I hover, it scales perfectly but the logo moves up a little bit. I tried transform-origin: center (even though that is the default) and nothing changed.
HTML
<div class="portfolio-projects">
<div class="project">
<img src="#" alt="">
</div>
</div>
CSS
portfolio-projects {
display: grid;
grid-gap: 50px;
margin: 50px 0;
max-width: 1050px;
.project {
position: relative;
cursor: pointer;
background-color: $gray;
max-width: 500px;
height: 325px;
overflow: hidden;
}
img {
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%,-35%) scale(.8);
transition: .2s;
}
.project:hover {
img {
transform: translate(-50%,-50%) scale(.9);
}
}
Wow. So I just needed to change it to this
.project:hover {
img {
transform: translate(-50%,-35%) scale(.9);
}
}
I forgot to adjust the hover after adjust the original value.

Flip animation is broken when having inside element with position property

Flip animation is not working correctly if it has some element inside with position property. This can be only reproduced on the first hover attempt after the page load.
Does anyone know why it has such behavior?
HTML:
<div class="parent">
<div class="card">
<div class="card__logo">
Logo
</div>
<div class="card__burger">
<div class="relative">Menu</div>
</div>
</div>
</div>
SCSS:
.card {
width: 90px;
height: 90px;
transition: transform 1s;
transform-style: preserve-3d;
&__logo,
&__burger {
position: absolute;
cursor: pointer;
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
backface-visibility: hidden;
background: #000;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
&__burger {
transform: rotateY(180deg);
}
}
.parent:hover {
.card {
transform: rotateY(180deg);
}
}
.relative {
position: relative;
}
Codeopen example
Update: I can reproduce this only in Chrome
I have different code but this will help you.
<style>
.flip-card {
background-color: transparent; width: 100px;
height: 100px; perspective: 1000px; margin-left:16%;
}
.flip-card-inner {
position: relative; width: 100%; height: 100%;
text-align: center; transition: transform 0.6s; transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner { transform: rotateY(180deg); }
.flip-card-front, .flip-card-back {
position: absolute; width: 100%;
height: 100%; backface-visibility: hidden;
}
.flip-card-front {
background-color: #ffffff; color: black; z-index: 2;
}
.flip-card-back {
background-color: #ffffff; color: white;
transform: rotateY(180deg); z-index: 1;
}
.coninstallbtn { margin-top: 31%; margin-left: 20%; }
</style>
<body>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
Front View
</div>
<div class="flip-card-back">
Back View
</div>
</div>
</div>
</body>

Weird CSS image hover

I'm creating a hover effect on an image with SCSS on a WordPress site (see gif: https://gyazo.com/1a35247e40d74b5fc756d508de4231eb)
As you see the image gets a "distorted" after hovering over it, maybe the ease-in property is wrong, or I'm not doing the hover effect properly. I'm wondering what I'm doing wrong in the code when it behaves like this.
This is the code that is working:
(left out some SCSS because it was so wast but the & is used to use parent class)
Edit: The HTML & SCSS
<div class="project_container">
<div class="project_content">
Test event
<br>
2018
</div>
<img src="http://testsite.com/wp-content/uploads/2018/12/img.jpg" class="attachment-full aligncenter">
</div>
-
&_container {
position: relative;
height: 300px;
width: 300px;
&:hover {
& > img {
opacity: .2;
}
& > .project_content {
opacity: 1;
}
}
& img {
position: absolute;
width: 100%;
height: 100%;
/*
object-fit: none;
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
*/
// Hover tranisiton
transition: opacity .5s;
}
}
&_content {
opacity: 0;
transition: opacity .5s;
// Center Position
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: $purple;
z-index: 2;
text-transform: uppercase;
font-size: 20px;
font-weight: 500;
text-align: center;
}
}
So using :hover; on the &_container gives the project_content: opacity: 1;. Then it also blurs the background image with the opacity: .2;, and the effect is achieved with a transition;
Thank you!
I rewrote everything with the hover effect so now I use an overlay class which has opacity: 0; on it (and a transition that takes care of the effect on :hover)
This is a simple version of the HTML:
<div class="project_container">
<div class="project_content">
<p>Content</p>
</div>
<img src="#" alt="test">
<div class="project_overlay"></div>
</div>
and the simplified SCSS:
.project {
&_container {
position: relative;
height: 300px;
width: 300px;
&:hover .project_overlay,
&:hover .project_content {
opacity: 1;
transition: opacity .5s;
}
}
& img {
position: absolute;
width: 100%;
height: 100%;
}
&_overlay {
background-color: rgba(255, 255, 255, .5);
position: absolute;
height: 100%;
width: 100%;
opacity: 0;
transition: opacity .5s;
}
}

Flip a 3D card with CSS

I'm trying to make a 3D card flipping effect with CSS like this.
The difference is that I want to use only CSS to implement it.
Here is the code I tried:
/*** LESS: ***/
.card-container {
position: relative;
height: 12rem;
width: 9rem;
perspective: 30rem;
.card {
position: absolute;
width: 100%;
height: 100%;
div {
position: absolute;
height: 100%;
width: 100%;
}
.front {
background-color: #66ccff;
}
.back {
background-color: #dd8800;
backface-visibility: hidden;
transition: transform 1s;
&:hover {
transform: rotateY(180deg);
}
}
}
}
HTML:
<div class="card-container">
<div class="card">
<div class="front"><span>Front</span></div>
<div class="back"><span>Back</span></div>
</div>
</div>
The issue is that the card doesn't flip, it snaps from back to front like this:
Is it possible to implement this 3d card flip on hover effect using only CSS?
I simplified the code to make it shorter and make the 3d card flip on hover. The card flips on the Y axis from the front face to the back face this is what it looks like:
Here is an example of a simple CSS only flipping card the flip animation is launched on hover :
.card {
position: relative;
width: 50vh;
height: 80vh;
perspective: 500px;
margin: 10vh auto 50vh;
}
.front,
.back {
position: absolute;
width: 100%;
height: 100%;
transition: transform 1s;
backface-visibility: hidden;
transform-style: preserve-3d;
}
.front {
background-color: #66ccff;
}
.back {
background-color: #dd8800;
transform: rotateY(180deg);
}
.card:hover .front {
transform: rotateY(180deg);
}
.card:hover .back {
transform: rotateY(360deg);
}
<div class="card">
<div class="front"><span>Front</span></div>
<div class="back"><span>Back</span></div>
</div>
Note that you will need to add vendor prefixes depending on the browsers you want to support. See canIuse for 3d transforms and transitions.
This is what I changed in your code for the flip effect:
the front face wasn't rotated on th Y axis on hover
the hover effect was launched when the .back div was hovered. This can create flickering as that div is rotating and "disapears" at mid rotation. It's better to launch the animation when the static parent is hovered.
the first parent isn't really usefull so I removed it
yes it can be done using CSS only and you can do by using CSS3 animation property. Here is example of flipping card animation.
<div class="container text-center">
<div class="card-container">
<div class="card">
<div class="front">
<span class="fa fa-user"></span>
</div>
<div class="back">User</div>
</div>
</div>
The CSS
.card-container {
display: inline-block;
margin: 0 auto;
padding: 0 12px;
perspective: 900px;
text-align: center;
}
.card {
position: relative;
width: 100px;
height: 100px;
transition: all 0.6s ease;
transform-style: preserve-3d;
}
.front, .back {
position: absolute;
background: #FEC606;
top: 0;
left: 0;
width: 100px;
height: 100px;
border-radius: 5px;
color: white;
box-shadow: 0 27px 55px 0 rgba(0, 0, 0, 0.3), 0 17px 17px 0 rgba(0, 0, 0, 0.15);
backface-visibility: hidden;
}
.front {
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
}
.back {
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
}
.card-container:hover .card {
transform: rotateY(180deg);
}
.back {
transform: rotateY(180deg);
}
You can also read this article about CSS Flip Animation on Hover
You can also find demo and download source from the article.

Resources