Transform scale change position element after in hover [duplicate] - css

This question already has an answer here:
How to keep origin in center of image in scale animation?
(1 answer)
Closed 4 years ago.
I try using transform:scale(1.2) to obtain the effect of an appearing circle around the icon. transform I added to the .icon-style:hover::after.
Now this code is commented, please uncomment this code to see what I want to get.
For example I trying doing something like this: click. But scale change position circle.
I read this article, but I don't now how to use transform-origin in my CSS.
Demo: JSFiddle
*{
background-color: black;
}
.pos-footer {
position: absolute;
bottom: 20px;
right: 30px;
}
.icon-social {
display: flex;
}
.icon-social-pos {
position: relative;
}
.icon-style {
position: relative;
background-repeat: no-repeat;
background-position: center;
width: 30px;
height: 30px;
background-color: rgba(255, 255, 255, 0.25);
padding: 10px;
border-radius: 50%;
transition: background-color .3s ease-in-out;
}
.icon-style:hover {
background-color: rgba(255, 255, 255, 0.7);
}
.icon-style::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
width: 100%;
height: 100%;
border: 5px solid rgba(255, 255, 255, 0.425);
border-radius: 50%;
padding: 7px;
opacity: 0;
transition: all .4s ease-in-out;
}
.icon-style:hover::after {
opacity: 1;
/* transform: scale(1.2); */
}
.icon-github {
background-image: url("https://img.icons8.com/windows/30/000000/github.png");
margin-right: 10px;
}
.icon-linkedin {
background-image: url("https://img.icons8.com/ios-glyphs/22/000000/linkedin-2.png");
margin-left: 10px;
}
<div class="pos-footer">
<div class="icon-social">
<a href="#">
<div class="icon-social-pos">
<div class="icon-style icon-github"></div>
</div>
</a>
<a href="#">
<div class="icon-social-pos">
<div class="icon-style icon-linkedin"></div>
</div>
</a>
</div>
</div>

First of all, the transform in your hover (.icon-style:hover::after) is overwriting your transform: translate(-50%, -50%);. A way to fix it is to add the translate to the hover too:
.icon-style:hover::after {
opacity: 1;
transform: scale(1.2) translate(-50%, -50%);
}
Then you have to define your transform-origin in .icon-style to top left;
*{
background-color: black;
}
.pos-footer {
position: absolute;
bottom: 20px;
right: 30px;
}
.icon-social {
display: flex;
}
.icon-social-pos {
position: relative;
}
.icon-style {
position: relative;
background-repeat: no-repeat;
background-position: center;
width: 30px;
height: 30px;
background-color: rgba(255, 255, 255, 0.25);
padding: 10px;
border-radius: 50%;
transition: background-color .3s ease-in-out;
}
.icon-style:hover {
background-color: rgba(255, 255, 255, 0.7);
}
.icon-style::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: top left;
z-index: 1;
width: 100%;
height: 100%;
border: 5px solid rgba(255, 255, 255, 0.425);
border-radius: 50%;
padding: 7px;
opacity: 0;
transition: all .4s ease-in-out;
}
.icon-style:hover::after {
opacity: 1;
transform: scale(1.2) translate(-50%, -50%);
}
.icon-github {
background-image: url("https://img.icons8.com/windows/30/000000/github.png");
margin-right: 10px;
}
.icon-linkedin {
background-image: url("https://img.icons8.com/ios-glyphs/22/000000/linkedin-2.png");
margin-left: 10px;
}
<div class="pos-footer">
<div class="icon-social">
<a href="#">
<div class="icon-social-pos">
<div class="icon-style icon-github"></div>
</div>
</a>
<a href="#">
<div class="icon-social-pos">
<div class="icon-style icon-linkedin"></div>
</div>
</a>
</div>
</div>

Related

CSS border-bottom-left-radius not applying in mozilla in a :before part [duplicate]

I have a card-element (bootstrap-4) with a front and back, on hover the back side is shown.
In order to create a "folded corner effect" I am using a pseudo-element(:before) on the front card, which works fine for all browsers except of firefox.
The bottom-left corner of the pseudo-element should also be rounded, so I set a border-radius. Unfortunately in Firefox the corner is not rounded, instead there is a strange box shown in the pseudo-element.
Any ideas what is causing this issue in Firefox? I already played around with positioning, z-index, overflow etc. but I cannot find the root cause.
Thanks a lot in advance!!
https://jsfiddle.net/rbv5ob20/
HTML:
.card {
color: white;
border: transparent;
border-radius: 10px;
-webkit-box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
}
.front,
.back {
width: 100%;
height: 150px;
background: #99d0e9;
opacity: 1;
backface-visibility: hidden;
overflow: hidden;
border-radius: 10px 0px 10px 10px;
}
.front {
position: absolute;
left: 0;
z-index: 1;
opacity: 1;
text-align: left;
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
}
.front::before {
content: "";
position: absolute;
top: 0px;
right: 0px;
border-width: 0px 25px 25px 0px;
border-style: solid;
border-color: transparent #f6f6f6 #32a2d4 transparent;
border-bottom-left-radius: 10px;
}
.back {
background: #32a2d4;
opacity: 1;
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
text-align: right;
border-top-right-radius: 10px;
display: block;
}
.card:hover .back {
-webkit-transform: rotateY(0);
-ms-transform: rotateY(0);
transform: rotateY(0);
}
.card:hover .front {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
<section id="offering" style="background-color:#f6f6f6;">
<div class="container">
<div class="col-4 text-center">
<div class="card">
<div class="front">
this is front...
</div>
<div class="back">
this is back
</div>
</div>
</div>
</div>
</section>
In Firefox border-radius doesn't seem to get properly applied to elements with a width and height of 0. A possible workaround to this would be to make a wrapper with overflow: hidden and a border-radius on its own:
.roundArrow {
border-radius: 0 0 0 10px;
width: 50px;
height: 50px;
overflow: hidden;
}
.roundArrow:after {
content: "";
display: block;
top: 0px;
right: 0px;
border-width: 0px 50px 50px 0px;
border-style: solid;
border-color: transparent #f6f6f6 #32a2d4 transparent;
}
<div class="roundArrow"></div>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.card {
color: white;
border: transparent;
border-radius: 10px ;
-webkit-box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
}
.front, .back {
width: 100%;
height:150px;
background: #99d0e9;
opacity: 1;
backface-visibility: hidden;
overflow: hidden;
border-radius: 10px 0px 10px 10px;
}
.front {
position: absolute;
left: 0;
z-index: 1;
opacity:1;
text-align:left;
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
}
.front::before {
content: "";
position: absolute;
top: 0px;
right: 0px;
border-bottom-left-radius: 10px;
height: 25px;
width: 25px;
background: #32a2d4;
}
.front::after {
content: "";
position: absolute;
top: -11px;
right: -17px;
height: 28px;
width: 35px;
background: white;
transform: rotate(45deg);
}
.back {
background: #32a2d4;
opacity: 1;
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
text-align:right;
border-top-right-radius: 10px;
display: block;
}
.card:hover .back {
-webkit-transform: rotateY(0);
-ms-transform: rotateY(0);
transform: rotateY(0);
}
.card:hover .front {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
</style>
</head>
<body>
<section id="offering" style="background-color:#f6f6f6;">
<div class="container">
<div class="col-4 text-center">
<div class="card">
<div class="front">
this is front...
</div>
<div class="back">
this is back
</div>
</div>
</div>
</div>
</section>
</body>
</html>
Following changes of ::before pseudo-element may work for you and you also have to add ::after pseudo-element for this solution.
.front::before {
content: "";
position: absolute;
top: 0px;
right: 0px;
border-bottom-left-radius: 10px;
height: 25px;
width: 25px;
background: #32a2d4;
}
.front::after {
content: "";
position: absolute;
top: -11px;
right: -15px;
height: 25px;
width: 35px;
background: white;
transform: rotate(40deg);
}

Cannot convert divider in responsive design

I have created a template which have the page divided in two sections, when I display the site in a desktop resolution all works well, but when I run the site on a smartphone I get the half circle on top and the divider between the two images, not responsive:
Essentially the half red circle, should be reduced in a smartphone resolution, and the divider goes outside the two images, this is what I tried so far:
#media (max-width: 800px) {
.divider{
top: 14.5%;
left: 50%;
height: 64.2%;
transform: translateX(-50%);
}
.circle{
top: -45%;
left: 50%;
width: 500px;
height: 400px;
border-radius: 50%;
}
.logo{
top: 0.5%;
left: 22.5%;
}
}
the problem's that this doesn't cover all the resolution case, so the problem is not fixed at all.
Is there a way to handle all the resolutions and make that template really responsive?
This is my fiddle.
SNIPPET:
body {
background-color: #ffffff;
}
/*Overlay*/
.hovereffect {
width: 50%;
height: 90vh;
float: left;
overflow: hidden;
position: relative;
text-align: center;
cursor: default;
background: #a7151f;
}
.hovereffect .overlay {
width: 100%;
height: 100%;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
padding: 50px 20px;
justify-content: center;
flex-direction: column;
display: flex;
}
.hovereffect img {
float: left;
width: 50%;
height: 90vh;
display: block;
position: relative;
max-width: none;
width: calc(100% + 20px);
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(-10px, 0, 0);
transform: translate3d(-10px, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.hovereffect:hover img {
opacity: 0.4;
filter: alpha(opacity=40);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.hovereffect h2 {
text-transform: uppercase;
color: #fff;
text-align: center;
position: relative;
font-size: 40px;
overflow: hidden;
padding: 0.5em 0;
background-color: transparent;
opacity: 0;
filter: alpha(opacity=0);
}
.hovereffect h2:after {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 2px;
background: #fff;
content: '';
-webkit-transition: -webkit-transform 0.35s;
transition: transform 0.35s;
-webkit-transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);
}
.hovereffect:hover h2:after {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.hovereffect a,
.hovereffect p {
color: #FFF;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: translate3d(100%, 0, 0);
transform: translate3d(100%, 0, 0);
}
.hovereffect:hover a,
.hovereffect:hover p,
.hovereffect:hover h2 {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
font-size: 16px;
}
/*DIVISORE*/
.middle {
position: absolute;
z-index: 9999;
}
.divider {
border-right: 5px solid #a7151f;
position: absolute;
z-index: 10;
top: 14.5%;
left: 50%;
margin: 0;
padding: 0;
width: auto;
height: 76.2%;
line-height: 0;
text-align: center;
text-transform: uppercase;
transform: translateX(-50%);
}
.circle {
z-index: 10;
position: absolute;
top: -250px;
left: 50%;
border: 5px solid #a7151f;
margin: 0;
padding: 0;
height: 100%;
line-height: 0;
text-align: center;
text-transform: uppercase;
transform: translateX(-50%);
background-color: #a7151f;
width: 500px;
height: 400px;
border-radius: 50%;
}
.first {
background-image: url('https://demos.creative-tim.com/material-kit-pro/assets/img/dg1.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.second {
background-image: url('https://demos.creative-tim.com/material-kit-pro/assets/img/bg9.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.logo {
top: 2.5%;
position: absolute;
left: 41.5%;
width: 200px;
margin: 0 auto;
}
<link href="https://demos.creative-tim.com/material-kit-pro/assets/css/material-kit.min.css" rel="stylesheet"/>
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Site
</title>
</head>
<body class="sections-page sidebar-collapse">
<div class="main">
<div class="container-fluid">
<div class="row">
<div class="hovereffect">
<img class="first">
<div class="overlay">
<h2>First</h2>
<p>
Explore
</p>
</div>
</div>
<span class="divider"></span>
<img class="img-responsive center-block circle">
<span class="circle">
</span>
<img src="#" class="logo" style="z-index: 9999">
<div class="hovereffect">
<img class="second">
<div class="overlay">
<h2>Second</h2>
<p>
Explore
</p>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="row align-items-center justify-content-xl-between">
<div class="col-6">
<div class="copyright text-center text-xl-left text-muted">
© 2019 Credit
</div>
</div>
<div class="col-6">
<div class="row">
Privacy Policy
Terms & Conditions
</div>
</div>
</div>
</div>
</footer>
</div>
</body>
</html>
This kind of layout can be achieved with Flexbox with many fewer lines of code. Also, much less HTML markup is required.
Total responsiveness is achieved combining the flexbox behavior with relative units (%, vh, vw).
I put several comments in the CSS to explain what each rule is doing.
body { margin: 0; }
.the-container {
position: relative;
overflow: hidden;
height: 100vh; /* fill the screen */
width: 100vw; /* fill the screen */
}
.the-circle {
position: absolute; /* overlap the pics, removes it from the box flow */
background-color: #a7151f;
border-radius: 50%; /* rectangle becomes an ellipse */
width: 60vw;
height: 30vh;
top: -15vh; /* half of the height */
left: 0; /* these 3 lines... */
right: 0; /* ...keep the "circle"... */
margin: auto; /* ...centered at the top */
}
.the-image-wrapper {
display: flex; /* easy responsive columns */
height: 100%; /* fill the screen */
}
.the-image-wrapper > div {
flex: 1 0 auto; /* items inside the wrapper will grow to fit avilable space */
}
.the-image-wrapper > div.the-divider {
flex: 0 1 5px; /* this divider item will not grow, and will be 5px wide */
background-color: #a7151f;
}
.first {
background-image: url('https://demos.creative-tim.com/material-kit-pro/assets/img/dg1.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.second {
background-image: url('https://demos.creative-tim.com/material-kit-pro/assets/img/bg9.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
<div class="the-container">
<div class="the-circle"></div>
<div class="the-image-wrapper">
<div class="first"></div>
<div class="the-divider"></div>
<div class="second"></div>
</div>
</div>

How do I animate a square around a block?

My animation works but after one turn, the square rotate of 45 deg,
I don't understand why.
https://codepen.io/igamanstudio/pen/ZPYWWO
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: spin 20s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url("https://loremflickr.com/60/60/girl/all") center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>
transform: rotate(45deg);
transform-origin: center;
background: red ;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
First you need to set the same duration for both animation then you need to use rotate(-315deg) for the image since you are setting rotate(45deg). The difference should be 360deg like the main container that will animate from 0deg to 360deg
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
//background: rgba(0,0,0,0.3);
animation: spin 5s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url('https://loremflickr.com/60/60/girl/all') center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-315deg);
transform: rotate(-315deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>

Span position absolute is not centered with top and left

I want to create a "X" with css spans and position absolute, but the spans aren't centered even if they should.
The container has the font-size of 1px. and a height and width of 100em. Therefore I can use 1em as 1% of the parents size.
I used transform-origin: 0px 5em; on the span, to rotate it without changing the starting point. The Element starts in 20% top and left (20em) and ends in 80% (top and left).
To get the required width i simply calculated: Square root( square of (60) * 2) (Pythagorean theorem) (60 because start and end 20 -- 100-20*2)
But for some reason the X is clearly not centered. Do you know what i did wrong?
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 20em;
left: 20em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 20em;
left: 80em;
}
.check.red:hover span
{
width: 84.852813742em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>
This isn't an automatic solution, but changing some values in your css i solved it:
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 18em;
left: 22em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 18em;
left: 78em;
}
.check.red:hover span
{
width: 78em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>
There are a few things you can do to make life easier here.
Firstly you can transform origin using a percentage, which means you don't need to calculate it yourself.
You can also position using a percentage, then offset using a transform (again with a percentage) to center no matter the size.
You can also set the width of the cross using a percentage, which will take it size from its parent.
Update:
Change the cross to animate from the top, rather than the center by using background gradients.
.check
{
position: relative;
height: 200px;
width: 200px;
background-color: white;
border-radius: 50%;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 20px;
width: 0%;
background: linear-gradient(to right, white 50%, red 50%);
background-size: 200% 100%;
background-position: left bottom;
top: 50%;
left: 50%;
transform-origin: center;
transition: background 0.3s ease;
}
.check.red span
{
transform: translate(-50%, -50%) rotate(-45deg);
}
.check.red span:last-child
{
transform: translate(-50%, -50%) rotate(-135deg);
}
.check.red:hover span
{
background-position: right bottom;
width: 70%;
}
<div class="check red">
<span></span>
<span></span>
</div>
Try this
use margin-top:-0.5rem;
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s; margin-top:-0.5rem;
}
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s; margin-top:-0.5rem;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 20em;
left: 20em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 20em;
left: 80em;
}
.check.red:hover span
{
width: 84.852813742em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>

How to make background scale from center outwards with CSS transition

I am trying to replicate the effect when you hover over a date with Material UI's date picker here (click on any text input to trigger the picker, then hover over a day) where the background expands outwards from the center.
I've tried to copy the CSS from here, but I've only managed to get the opposite working. See: https://jsfiddle.net/2zkofa0x/3/
My CSS:
span:hover {
color: #fff;
background: rgba(0, 151, 167, 0.5);
border-radius: 50%;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
}
Would anyone know how I can have the coloured background spread out and fill from the center of the element (opposite of what I've got above)?
You could try like this. It puts the hover effect on a parent div so the hit target is always there.
Also, the circle needs to start off at a scale of 0 so it can expand to the full size during the transition.
HTML:
<div class='container'>
<div class='circle'>
</div>
<span>42</span>
</div>
CSS:
div.container {
position: relative;
height: 30px;
width: 30px;
}
div.container > div.circle {
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
width: 30px;
height: 30px;
transform: scale(0);
transition: all 450ms ease 0ms;
}
div.container:hover > div.circle {
background: rgba(0, 151, 167, .5);
border-radius: 50%;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
}
div.container span {
position: relative;
padding: 7px;
line-height: 30px;
}
div.container:hover span {
color: rgb(255, 255, 255);
}
https://jsfiddle.net/2zkofa0x/18/
Use box-shadow
li { position: relative; display: inline-block; padding: 10px; }
li:before {
content: '';
height: 1px;
width: 1px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 0 0px #18b;
border-radius: 50%;
background: #18b;
transition: all .3s;
opacity: 0;
z-index: -1;
}
li:hover:before {
box-shadow: 0 0 0 15px #18b;
opacity: 1;
}
<ul>
<li>1</li>
<li>2</li>
</ul>
You could try something like this. You could also use jquery to get the same effect.
/* Material style */
button {
height: 200px;
width: 200px;
border: none;
cursor: pointer;
color: white;
padding: 15px;
border-radius: 360px;
font-size: 22px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
background: #2196F3;
}
/* Ripple magic */
button{
position: relative;
overflow: hidden;
}
button:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 5px;
height: 5px;
background: rgba(255, 255, 255, .5);
opacity: 0;
border-radius: 50%;
transform: scale(1, 1) translate(-50%);
transform-origin: 50% 50%;
}
#keyframes ripple {
0% {
transform: scale(0, 0);
opacity: 1;
}
20% {
transform: scale(25, 25);
opacity: 1;
}
100% {
opacity: 0;
transform: scale(40, 40);
}
}
button:focus:not(:active)::after {
animation: ripple 1s ease-out;
}
/* On Hover */
.ripple-button1{
position:relative;
width:200px;
height:200px;
background-color:#99C;
color:#FFF;
border-radius:360px;
text-decoration:none;
text-align:center;
vertical-align:middle;
display:table-cell;
box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
}
.wave1{
position:absolute;
width:200px;
height:200px;
background-color:#FFF;
top:0;
left:0;
transform: scale(0);
opacity:0.5;
border-radius:300px;
}
.ripple-button1:hover > .wave1{
animation: ripple-in1 2s;
}
#keyframes ripple-in1 {
0% {transform: scale(0);}
20%{transform: scale(1);opacity:0.3;}
100%{transform: scale(1);opacity:0;}
}
<h3>Ripple on Click</h3>
<button>Click !</button>
<h3>Ripple on Hover</h3>
<div class="wave1"></div>Hover !
I was looking for the same. Thank you for raising. Though you have already chosen an answer, I'll share my hack which looks similar to the one on the quoted page.
div {
margin: 25px;
height: 100px;
width: 100px;
text-align: center; //Fix the element to center
}
span {
width: 50px;
height: 50px;
padding: 5px;
border-radius: 50%;
}
span:hover {
color: #fff;
background: rgba(0, 151, 167, 0.5);
padding: 15px; //Transform padding, width and height instead of border-radius
width: 20px;
height: 20px;
transform: scale(1);
transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 1ms;
}
<div>
<span>42</span>
</div>

Resources