Problem of blurring background image (svg) while using scale on hover - html

I need to zoom image in on hover and focus. On hover from .9 to 1 and on focus from 1 to 1.2.
The problem is that while scaling, the picture is blurry. No matter what size I start with, .9 or 1.
I used two solutions:
transform: scale3d(.9, .9, .9);
transform: translateZ(0) scale (.9, .9);
But it didn't work (solution in snippet).
What am I doing wrong? Maybe there are other solutions?
.button {
border: none;
background-color: transparent;
background-size: 100%;
background-position: center;
background-repeat: no-repeat;
background-image: url('https://svgshare.com/i/FWE.svg');
width: 28px;
height: 36px;
transition: transform .3s ease, background .3s ease, opacity .2s ease;
box-shadow: none;
will-change: transform;
transform: scale3d(.9,.9,.9);
transform: translateZ(0) scale(.9, .9);
}
.button:hover {
cursor: pointer;
transform: scale3d(1,1,1);
transform: translateZ(0) scale(1, 1);
}
.button:focus {
outline: none;
transform: scale3d(1.2,1.2,1.2);
transform: translateZ(0) scale(1.2, 1.2);
}
<button class="button">
</button>
<button class="button">
</button>

You could put the image into a pseudo element and transition the size of that element - that way you will always keep a sharp svg (seems a lot sharper than any of the other ways we discussed in the comments):
.button {
cursor: pointer;
outline: none;
border: none;
width: 36px;
height: 36px;
background-color: transparent;
box-shadow: none;
position: relative;
}
.button:after {
content: '';
display: block;
background: url('https://svgshare.com/i/FWE.svg') center center no-repeat;
background-size: contain;
width: 26px;
height: 26px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
transition: all .15s linear;
}
.button:hover:after {
width: 30px;
height: 30px;
}
.button:focus:after {
width: 34px;
height: 34px;
}
<button class="button">
</button>
<button class="button">
</button>

Related

Hamburger toggle is not working on mobile

I made a hamburger toggle that is supposed to transform. On my laptop it shows perfectly but on my mobile nothing is done to it. It is just a checkbox on the left side. None of the styles were applied to it. I have media queries but none apply to this. It is bootstrap but I made a custom toggler.
#custom-toggler {
border: none;
float: right;
margin: 25px 15px 0 0
}
#custom-toggler input{
display: block;
width: 40px;
height: 32px;
position: relative;
top: -7px;
left: 5px;
float: right;
cursor: pointer;
opacity: 0; /* hide this */
z-index: 2; /* and place it over the hamburger */
-webkit-touch-callout: none;
}
#custom-toggler input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: white;
}
#custom-toggler span:first-child
{
transform-origin: 0% 0%;
}
#custom-toggler span:last-child
{
transform-origin: 0% 100%;
}
#custom-toggler input:checked ~ span:last-child
{
transform: rotate(-45deg) translate(0, -1px);
}
#custom-toggler input:checked ~ span:nth-child(2n-1)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#custom-toggler span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s
}
<nav class="small-nav navbar-light fixed-top ">
<a class="navbar-brand " href="index.html"><img id='logo'
src="../image/TreysCode-logo1.png"></a>
<div id='custom-toggler'>
<input type="checkbox" data-toggle="collapse" data-
target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" aria-expanded="false" aria-
label="Toggle navigation"/>
<span ></span>
<span ></span>
<span ></span>
</div>
Missing Vendor prefixes
Safari is one of those Browsers which still requires the -webkit-* prefix on most newer Styles.
Just turn every of the following
transform: ...;
transform-origin: ...;
transition: ...,
transform ...;
into
-webkit-transform: ...;
transform: ...;
-webkit-transform-origin: ...;
transform-origin: ...;
-webkit-transition: ...,
-webkit-transform ...,
transform ...;
transition: ...,
-webkit-transform ...,
transform ...;
If a browser sees the -webkit-* it will use it if it can, if not they get simply ignored and the next (non-prefixed) Style gets used.

Animate fontawesome Icon inside anchor tag to fly in onhover

I'm in need for a CSS/SCSS/SASS guru to help me determine what I am doing wrong with this simple animation.
Objective: What I'm trying to accomplish a simple animation in which the fontawesome icon fa-angle-right fly in from the left after the word, onHover. I figured this could be done with a display: none property and adding some transition to the parent property, but it's not animating as intended.
The caveat here is that I CANNOT change the HTML structure.
An example of what I'm trying to do; but granted this is using a different HTML structure & SVG instead of fontawesome icons
JSFiddle: https://jsfiddle.net/bwrmam9o/1/
HTML
<a href="#" class="btn ripple">
<i class="fa fa-left fa-location-arrow"></i>
<span class="label">View Location </span>
<i class="fa fa-right fa-angle-right fa-animate"></i>
</a>
SCSS/SASS
.btn{
display: inline-block;
color: #FFF;
background: #CB5039;
text-decoration: none;
font-family: Arial;
padding: 10px 12px;
text-transform: uppercase;
font-size: 13px;
font-weight: bold;
transition: all 0.1s cubic-bezier(0.16, 0.08, 0.355, 1);
.fa-left{
margin-right: 5px;
}
.fa-right{
margin-left: 5px;
}
.fa-animate{
display: none;
transition: all 0.1s cubic-bezier(0.16, 0.08, 0.355, 1);
}
&:hover{
background: blue;
.fa-animate{
display: inline-block;
}
}
}
.ripple {
position: relative;
overflow: hidden;
transform: translate3d(0, 0, 0);
}
.ripple:after {
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
pointer-events: none;
background-image: radial-gradient(circle, #FFF 10%, transparent 10.01%);
background-repeat: no-repeat;
background-position: 50%;
transform: scale(10, 10);
opacity: 0;
transition: transform .25s, opacity 1s;
}
.ripple:active:after {
transform: scale(0, 0);
opacity: .2;
transition: 0s;
}
Any help on this would be greatly appreciated!
is this what you want? modify style like this .
.fa-animate{
left: -15px;
position:relative;
opacity: 0;
transition: 1s;
}
&:hover{
background: blue;
.fa-animate{
left: 0;
opacity:1;
}
}
full edited code here : https://jsfiddle.net/jayakrishnancn/bwrmam9o/3/

how to make coin flip transform in css

So, I have an icon, a circle icon, I want to make this icon when it hovered it will has coin flip transform, just like https://desandro.github.io/3dtransforms/examples/card-02-slide-flip.html but it flip two times so it goes back to the first position.
This is the HTML code:
<div class="bg">
<div class="icon">
<img src="football.png">
</div>
</div>
This is the CSS code:
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg );
}
so the transform is not soft like the example from the link, and when the first flip (or rotation) I want to change the icon with different image, but when the second rotate it will back to first image. Any suggestion? thanks before
You forgot to add the animation itself, the transition.
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
/* TRANSITION HERE!! */
-webkit-transition: transform 1s ease;
-moz-transition: transform 1s ease;
-ms-transition: transform 1s ease;
-o-transition: transform 1s ease;
transition: transform 1s ease;
/* END OF TRANSITION */
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg ); /* ALSO EXTRA TRANSFORM PROPERTIES ADDED FOR COMPATIBILITY*/
-ms-transform: translateX( -1px ) rotateY(180deg); /* IE 9 */
-webkit-transform: translateX( -1px ) rotateY(180deg); /* Chrome, Safari, Opera */
}
<div class="bg">
<div class="icon">
<img src="https://i.stack.imgur.com/RVjde.jpg">
</div>
</div>
I hope this helped.
Cheers!
You can define an animation the following:
#keyframes flip_animation {
from {transform: rotateY(0deg);}
to {transform: rotateY(360deg);}
}
And add this animation you your CSS-Class
.icon:hover {
animation-name: flip_animation;
animation-duration: 1s;
}
See this link for more information about animations in CSS.

CSS - How to remove thin white line between :after element and blue border on hover on image

This is my structure:
<div class="parent">
<a href="#">
<p class="carousel_img">
<span class="img"></span>
Some text
</p>
</a>
and this is my style:
.parent{
height: 270px;
width: 270px;
}
.img {
background-image: url(http://frontendtest.ru/anit/img/ps_3.jpg);
background-size: cover;
display: block;
height: 250px;
overflow: hidden;
border-radius: 50%;
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
-webkit-transition: -webkit-transform 0.3s;
transition: -webkit-transform 0.3s;
transition: transform 0.3s;
transition: transform 0.3s, -webkit-transform 0.3s;
background-repeat: no-repeat;
}
.carousel_img {
border-radius: 50%;
border: 4px solid #f6e9d6;
height: 260px;
width: 260px;
overflow: hidden;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
position: relative;
margin: 0 auto;
}
a:hover .carousel_img {
border-color: #2e8ce4;
}
.carousel_img:before {
height: 15px;
width: 15px;
border-left: 2px solid #fff;
border-bottom: 2px solid #fff;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
margin: auto;
bottom: 20px;
z-index: 2;
}
.carousel_img:after {
content: '';
position: absolute;
left: 0;
right: 0;
display: none;
}
.carousel_img:after {
bottom: 0;
height: 56px;
background: #2e8ce4;
}
a:hover .carousel_img:before, a:hover .carousel_img:after {
display: block;
}
In Chrome, Firefox, Edge we can see a thin white line between blue :after element and blue border on bottom of picture when we :hover on image. This is a link on my pen http://codepen.io/DmitryShutov/pen/JKovYb.
How can I remove thin white line?

Scaling image with CSS Transition

This is how I want to scale my images, smoothly without any jumps.
My attempt does not work like in the gallery above, the image (red square in my case) jumps, my code:
section {
background-color: rgba(0, 0, 0, 0.701961);
width: 400px;
height: 400px;
}
div {
position: absolute;
top: 120px;
left: 120px;
width: 160px;
height: 160px;
background-color: red;
-webkit-transition: all .2s ease-in-out;
}
div:hover {
-webkit-transform: scale(1.8);
}
<section>
<div></div>
</section>
How to fix this? The red square jumps. Is it possible to scale smoothly with CSS Transition at all like in the gallery in the link at the beginning?
What do you mean by "jumps"? Try this, jumps too?
section {
background-color: rgba(0, 0, 0, 0.701961);
width: 400px;
height: 400px;
}
div {
position: absolute;
top: 120px;
left: 120px;
width: 160px;
height: 160px;
background-color: red;
-webkit-transition: -webkit-transform 0.4s;
transition: transform 0.4s;
}
div:hover {
-webkit-transform: scale(1.8) rotate(0.01deg);
transform: scale(1.8) rotate(0.01deg);
}
<section>
<div></div>
</section>
Also, you could try the variant with a container for an image (like in the first link of your question).
JSFiddle
.banner {
position: relative;
z-index: 1;
cursor: pointer;
border: 1px solid #dfe2e5;
background: #000;
width: 310px;
height: 150px;
-webkit-transition: border-color 0.1s;
transition: border-color 0.1s;
overflow: hidden;
}
.banner:hover {
border-color: #bdc1c5;
}
.banner__image-container {
overflow: hidden;
height: 100%;
}
.banner__image {
-webkit-transition: all 0.4s;
transition: all 0.4s;
}
.banner:hover .banner__image {
-webkit-transform: scale(1.15) rotate(0.01deg);
transform: scale(1.15) rotate(0.01deg);
opacity: 0.5;
}
<div class="banner">
<div class="banner__image-container">
<img class="banner__image" src="https://picsum.photos/310/150/?image=1022"/>
</div>
</div>
I sometimes solve strange jumps on transition by adding rotate(0.01deg) on the transform property, like so:
.element:hover {
transform: scale(1.5) rotate(0.01deg);
}