CSS text isn't showing instantly after gradient is drawn - html

I am having a weird issue. This only happens on the initial card flip.
I have text that shows on top of a gradient background. This background image shows on mouse hover.
The text takes a split second to show and then it just pops in. I need the text to already be there when the image is flipped or at least have a smooth transition in if this isn't possible. I have traced it down to the placement of the text in different corners of the image. If I remove the css for the placement of the text then it shows and works fine.
Here is the Html
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img [src]="sanitizer.bypassSecurityTrustUrl('data:'+image.mimeType+';base64, '+image.frontImage)" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="flip-card-back linear-gradient">
<h1 class="info">{{getTitle()}}</h1>
<p class="info-bottom-right">{{getTitle()}}</p>
<p class="info-bottom-left">{{getTitle()}}</p>
</div>
</div>
</div>
Here is the css
.flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px; /* Remove this if you don't want the 3D effect */
}
/* This container is needed to position the front and back side */
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
/* Do an horizontal flip when you move the mouse over the flip box container */
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
cursor: pointer;
}
/* Position the front and back side */
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
/* Style the front side (fallback if image is missing) */
.flip-card-front {
background-color: #bbb;
color: black;
}
/* Style the back side */
.flip-card-back {
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}
.info{
display: block;
position: absolute;
top: 10px;
left: 10px;
color: #fff;
font-weight: bold;
}
.info-bottom-right{
display: block;
position: absolute;
top: 10px;
right: 10px;
color: #fff;
font-weight: bold;
}
.info-bottom-left{
display: block;
position: absolute;
bottom: 10px;
left: 10px;
color: #fff;
font-weight: bold;
}
Here is a stackblitz showing the actual issue
https://stackblitz.com/edit/angular-eyo4a8-sura86?file=app%2Fdatepicker-date-class-example.css

It turns out this is a known bug with Chromium browsers - this thread finally shed some light on it. All you have to do is add preserve-3d to the front and back classes.
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
transform-style: preserve-3d;
}

The transition : transform 0.8s; applies also to the text so it adds a small delay to the text to appear when the cards flips. If you change it to 0.3s the card will flip faster but the text will also appear faster

Related

How to turn image to black and make text appear on hover using css?

I am making a gallery of imgage as a feature on my website, the gallery will represent the images as a grid.
I would like to be able to hover over a grid item and have the image turn to complete black and have text overlay on top in white but struggling to structure this effect using CSS.
I am targeting 'post_feature_outer' and effecting the colour of the text within that div from transparent to white.
The text is appearing white when hovering on the square as expected. I would also like the image to turn completely black as well
CSS filter does not work as this also removes the text, does anyone know how to get the effect?
Below is an example of what I mean when no hovering vs hovering on the tile.
Thank You
NO HOVER:
HOVER:
Thank you!
.post_feature_outer {
color: rgba(0, 0, 0, 0);
}
.post_feature_outer:hover {
color: white;
}
/* added by community for clarity */
body {
background: #222;
}
<div class='post_feature_outer'>
<h1 class="post_feature_title">VOGUE ITALIA – JUNE 2022 ISSUE</h1>
<img class="post_feature_img" src="https://via.placeholder.com/300x200" />
</div>
i think this helps:
.post_feature_outer {
width: 600px;
height: 200px;
position: relative;
}
.post_feature_title {
margin: 0;
align-items: center;
justify-content: center;
background-color: black;
color: white;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
display: none;
}
.post_feature_img {
width: 100%;
height: 100%;
}
.post_feature_outer:hover .post_feature_title {
display: flex;
}
<div class='post_feature_outer'>
<h1 class="post_feature_title">VOGUE ITALIA – JUNE 2022 ISSUE</h1>
<img class="post_feature_img" src="https://upload.wikimedia.org/wikipedia/commons/8/84/Flag_of_Uzbekistan.svg" />
</div>
I think I'd use absolute positioning to layer the heading and image, along with opacity for the show/hide effect.
.post_feature_outer {
background-color: #000;
display: inline-block;
position: relative;
}
.post_feature_title {
position: absolute;
top: 50%;
left: 0;
width: 100%;
transform: translateY(-50%);
text-align: center;
transition: all 0.3s;
color: white;
opacity: 0;
}
.post_feature_img {
transition: all 0.3s;
font-size: 0;
display: block;
}
.post_feature_outer:hover .post_feature_title {
opacity: 1;
}
.post_feature_outer:hover .post_feature_img {
opacity: 0;
}
<div class='post_feature_outer'>
<div class="post_feature_title">
<h1>VOGUE ITALIA – JUNE 2022 ISSUE</h1>
</div>
<img class="post_feature_img" src="https://via.placeholder.com/300x200" />
</div>

How can I setup hover animation for mobile view?

I'm brand new here so I hope my question makes sense.
I need to adjust the hovering system for my images. I have 2 - front and back. When the user hovers (clicks on mobile) on the front it should display the back. When the cursor leaves the element it should display the front again.
This doesn't work on mobile. When the user clicks on the front, the back appears but then he/she has to click outside of the element to display the front again.
How can I make it that users can keep clicking on the image element to display the front and then the back?
Here's my code:
.flip-card {
background-color: transparent;
width: auto;
height: auto;
perspective: 1000px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
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%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
.flip-card-front {
background-color: #bbb;
color: black;
}
.flip-card-back {
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="https://petlifetoday.com/wp-content/uploads/2019/07/new-kitten-750x500.jpg" alt="Avatar" >
</div>
<div class="flip-card-back">
<img src="https://i.pinimg.com/originals/52/73/c8/5273c86755b215c1f3b4fac7bbad935c.jpg" alt="Avatar" >
</div>
</div>
</div>
Thank you
Use :focus where you set :hover
Doc: https://developer.mozilla.org/en-US/docs/Web/CSS/:focus

CSS scale and transform making text blury

I have some flip cards and when you hover over the flip card, the card flips and enlarges (scales). However I don't want to the text inside the hovered card to scale so I put the text inside a child div. (I only want the parent card background to scale).
How can I stop my text and content from scaling and going blurry? I've tried to reset my child div to 1/2 of the scale size to reset it but it does not work.
HTML
<div class="c-flip-card">
<div class="c-flip-card__inner">
<div class="c-flip-card__front"><img src="img_avatar.png" alt="Avatar"</div>
<div class="c-flip-card__back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
SASS
.c-flip-card {
background-color: transparent;
width: 180px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
/* Do an horizontal flip when you move the mouse over the flip box container */
&:hover {
z-index: 10;
position: relative;
}
&:hover .c-flip-card__inner {
transform: rotateY(180deg) scale(1.4);
}
/* This container is needed to position the front and back side */
.c-flip-card__inner {
cursor:pointer;
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
/* Position the front and back side */
.c-flip-card__front, .c-flip-card__back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
/* Style the front side (fallback if image is missing) */
.c-flip-card__front {
background-color: #bbb;
color: black;
}
/* Style the back side */
.c-flip-card__back {
background-color: red;
color: white;
transform: rotateY(180deg);
}
.abc{
transform: scale(0.7);
h1, p{
color:#000;
}
}
}
jsfiddle
Edit
I think I found a workaround : Don't use scale() !
.c-flip-card .c-flip-card__inner {
transition: all 0.8s;
}
.c-flip-card:hover .c-flip-card__inner {
transform: rotateY(180deg) translate3d(40px,-40px,0);
/* Just change the width and height to 140% and have them transition
I used translate3d to position the card the same way scale() does */
width: 140%;
height: 140%;
}
And if you want to get the same positioning as scale() produce, you can add something like translate3d(40px,-40px,0) to your transform.
This way you don't have to manage the size of the text, the effect is the same (except for a little transition on the text position), and there is no bluriness.
.c-flip-card {
margin: 50px;
background-color: transparent;
width: 180px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
}
.c-flip-card:hover {
z-index: 10;
position: relative;
}
.c-flip-card:hover .c-flip-card__inner {
transform: rotateY(180deg) translate3d(40px,-40px,0);
width: 140%;
height: 140%;
}
.c-flip-card .c-flip-card__inner {
cursor: pointer;
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: all 0.8s;
transform-style: preserve-3d;
}
.c-flip-card .c-flip-card__front,
.c-flip-card .c-flip-card__back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.c-flip-card .c-flip-card__front {
background-color: #bbb;
color: black;
}
.c-flip-card .c-flip-card__back {
background-color: red;
color: white;
transform: rotateY(180deg);
}
<div class="c-flip-card">
<div class="c-flip-card__inner">
<div class="c-flip-card__front">
<img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="c-flip-card__back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
Original
Putting the content of your back card inside a div and applying scale(0.7) on it seems to work but it really doesn't look good on the first hover.
<div class="c-flip-card__back">
<div class="notScale">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
.c-flip-card:hover .notScale {
transform: scale(0.7);
}
So instead of applying transform on your text, since it's only shown on hover, why not simply change the font size for exemple using calc() and variables :
/* define variables for p and h1 */
body {
--sizeP : 16px;
--sizeH1 : calc(2.5 * var(--sizeP));
}
/* apply those variable one "regular" h1 and p */
h1 {
font-size: var(--sizeH1);
}
p{
font-size: var(--sizeP);
}
/* "scale" down the text for the backside by a factor of .7 */
.c-flip-card .c-flip-card__back h1{
font-size: calc(.7 * var(--sizeH1));
}
.c-flip-card .c-flip-card__back p{
font-size: calc(.7 * var(--sizeP));
}
For the blury part I did get some imporvement (though it's not enough for chrome) by adding :
.c-flip-card {
-webkit-filter: blur(0);
filter: blur(0);
}
body {
--sizeP: 16px;
--sizeH1: calc(2.5 * var(--sizeP));
}
h1 {
font-size: var(--sizeH1);
}
p {
font-size: var(--sizeP);
}
/* The flip card container - set the width and height to whatever you want. We have added the border property to demonstrate that the flip itself goes out of the box on hover (remove perspective if you don't want the 3D effect */
.c-flip-card {
margin: 50px;
background-color: transparent;
width: 180px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px;
/* Do an horizontal flip when you move the mouse over the flip box container */
/* This container is needed to position the front and back side */
/* Position the front and back side */
/* Style the front side (fallback if image is missing) */
/* Style the back side */
-webkit-filter: blur(0);
filter: blur(0);
}
.c-flip-card:hover {
z-index: 10;
position: relative;
}
.c-flip-card:hover .c-flip-card__inner {
transform: rotateY(180deg) scale(1.39);
}
.c-flip-card .c-flip-card__inner {
cursor: pointer;
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.c-flip-card .c-flip-card__front,
.c-flip-card .c-flip-card__back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.c-flip-card .c-flip-card__front {
background-color: #bbb;
color: black;
}
.c-flip-card .c-flip-card__back {
background-color: red;
color: white;
transform: rotateY(180deg);
}
.c-flip-card .c-flip-card__back h1 {
font-size: calc(.7 * var(--sizeH1));
}
.c-flip-card .c-flip-card__back p {
font-size: calc(.7 * var(--sizeP));
}
<div class="c-flip-card">
<div class="c-flip-card__inner">
<div class="c-flip-card__front">
<img src="img_avatar.png" alt="Avatar" style="width:300px;height:300px;">
</div>
<div class="c-flip-card__back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
For chrome I tried every solution from here and here but wasn't able to get a descent result.
The only one that worked for the blury part on chrome was :
#supports (zoom : 140%) {
.c-flip-card:hover {
zoom : 140%;
transform: translate3d(-40px,-40px,0);
}
.c-flip-card:hover .c-flip-card__inner {
transform: rotateY(180deg) scale(1);
}
.c-flip-card .c-flip-card__back h1{
font-size: calc(var(--sizeH1));
}
.c-flip-card .c-flip-card__back p{
font-size: calc(var(--sizeP));
}
}
But I wasn't able to transition the property zoom so the effect isn't great.
I followed Amarjits solutions and added scale:1.1 to .c-flip-card__back and this is the best result, however it is blurry using Saffari
.c-flip-card__back {
background-color: red;
color: white;
transform: rotateY(180deg) scale(1.1);
}
I found a better solution. Just don't use scaling on the back card, so the animation just tweens as the front card fades out it just shows the back card
This transitions around half way creates the illusion of it scaling when in fact it's just showing a div at set height and width.
It works in Chrome and Saffari and text is not blurry
.mycont{
/* How pronounced should the 3D effects be */
perspective: 500;
-webkit-perspective: 500;
-moz-perspective: 500;
-ms-perspective: 500;
-o-perspective: 500;
width:100%;
height:245px;
position:relative;
/*Some UI */
border-radius:6px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
-ms-border-radius:6px;
-o-border-radius:6px;
font-size:28px;
line-height:150px;
vertical-align:middle;
cursor:pointer;
}
.box-front,.box-back{
/* Enable 3D transforms */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-o-backface-visibility: hidden;
width:100%;
height:100%;
position:absolute;
background-color:#0090d9;
/* Animate the transitions */
-webkit-transition:0.8s; text-align:center;
-moz-transition:0.8s; text-align:center;
-ms-transition:0.8s; text-align:center;
-o-transition:0.8s; text-align:center;
transition:0.8s; text-align:center;
color:#FFF;
border-radius:5px;
-webkit-border-radius:6px;
-moz-border-radius:6px;
-ms-border-radius:6px;
-o-border-radius:6px;
}
.box-back{
/* The back side is flipped 180 deg by default */
transform:rotateY(180deg);
-webkit-transform:rotateY(180deg);
-moz-transform:rotateY(180deg);
-ms-transform:rotateY(180deg);
-o-transform:rotateY(180deg);
background-color:#f35958;
}
.mycont:hover .box-front{
/* When the mycont is hovered, flip the front side and hide it .. */
transform:rotateY(180deg);
-webkit-transform:rotateY(180deg);
-moz-transform:rotateY(180deg);
-ms-transform:rotateY(180deg);
-o-transform:rotateY(180deg);
}
.mycont:hover .box-back{
/* .. at the same time flip the back side into visibility */
transform:rotateY(360deg);
-webkit-transform:rotateY(360deg);
-moz-transform:rotateY(360deg);
-ms-transform:rotateY(360deg);
-o-transform:rotateY(360deg);
margin-left: -0%;
margin-top: -10%;
width: 300px;
height:430px;
}
<div style="width:300px; margin-top:100px; margin-left:100px;">
<div class="mycont">
<div class="box-front">Front :)</div>
<div class="box-back">
rtrtrtrt
</div>
</div>
</div>

Keep text on foreground with scale effect on image

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>

How to vertically center image in this responsive, flippable circle?

In a Rails 3.2 app I am displaying user avatars using a responsive, flippable CSS circle. But due to padding needed on a parent element, the avatar is not centered in the circle.
How can I center this circle? Where possible, I would prefer to keep this semantically marked up with an img tag, rather than as a background image on a div.
Also, can this be optimized? I've a lot of nested divs at present!
The code is below, and a jsfiddle here.
<div class='responsive-container'>
<div class='responsive-inner'>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flip-inner">
<div class="front">
<div class="circle">
<div class="circle-inner">
<%= image_tag #user.avatar %>
</div>
</div>
</div>
<div class="back">
<div class="circle">
<div class="circle-inner">
<%= #user.name %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
.responsive-container{
position: relative;
width: 50%;
}
.responsive-container:before{
content: "";
display: block;
padding-top: 100%;
}
.responsive-inner{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.flip-container {
perspective: 1000;
-webkit-perspective: 1000; /* Safari and Chrome */
}
/* flip the pane when hovered */
.flip-container:hover .flip-inner, .flip-container.hover .flip-inner {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.flip-inner {
transition: 0.6s;
-webkit-transition: 0.6s; /* Safari */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d; /* Safari and Chrome */
position: relative;
}
.front, .back {
backface-visibility: hidden;
-webkit-backface-visibility:hidden; /* Chrome and Safari */
-moz-backface-visibility:hidden; /* Firefox */
-ms-backface-visibility:hidden; /* Internet Explorer */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.front {
z-index: 2;
}
.back {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.circle {
width: 100%;
height: 0;
padding: 50% 0; //padding top & bottom must equal width
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
overflow: hidden;
border: 1px #000 solid;
}
.circle-inner {
display: table;
width:100%;
}
.circle-inner img {
height: auto;
width: 100%;
}
.circle-inner p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
</style>
why dont you use border-radius instead of circle? will be much easier i think.
http://bavotasan.com/2011/circular-images-with-css3/