Rotating a shadow on social icons hover state - css

I've just started to work on a pure css set of social icons. Everything is going pretty smooth but I can't get this half circle shadow to rotate correctly.
The transition seems to be working correctly but the positioning of the shadow is not correct. It may be due to the axis point it is rotating on but it seems to be correct. Without any transition I can get the shadow aligned correctly with,
top: 7px;
right: 15px;
but the shadow's parent is positioned relative and should keep the shadow inside of it without problems. I also tried top, left 5px since there is a 5px border on it but this also did not work.
Here is the css for the shadow:
.shadow {
height: 45px;
width: 100%;
overflow: hidden;
position: absolute;
top: 7px;
right: 15px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
}
.shadow:before {
content: "";
width: 90px;
height: 90px;
position: absolute;
display: block;
border-radius: 50%;
background: rgba(0, 0, 0, 0.1);
}
.icon:hover .shadow {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
bottom: 7px;
left: 15px;
}
My Test Runs
Shadow without top, left, right, and bottom used: Demo
Full set of icons with top, left, right, and bottom used: Demo
With the use of transform-origin: Demo
I do know why, on the full set of icons, it is transitioning so poorly but I am unsure of how to align this shadow correctly. Any ideas on how I can get this shadow to rotate inside of the icon correctly?

You are fixing with margins what you should fix with transform origin
CSS
.shadow {
height: 45px;
width: 100%;
overflow: hidden;
position: absolute;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-webkit-transform-origin: center bottom;
-moz-transform-origin: center bottom;
transform-origin: center bottom;
}
.icon:hover .shadow {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
}
fiddle
I have removed left and top, and added transform origin. This must be at the bottom because you have only half a circle, and so the circle center is at the bottom.

Nice icons! You were very close. You just needed the hover margin to adjust from the same side.
http://jsfiddle.net/SVHny/7/
.icon:hover .shadow {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
bottom: 7px;
right: -15px;
}

Related

Hover effect in circle border

can someone help me to do this hover effect
it is a normal circle
and when passing over it I would like it to look that way and even for the circle to rotate
Thanks in advance
If I understand you correctly, here is one way you could make this work.
There are 3 elements to this; the image, the circle and the gap.
The circle is a div with a border-radius to round it out, and a border with the color of your choice.
The gap is a div that is the full height of the wrapper and the width of the intended gap. The div is given the same color as the background (white in this case - change to whatever you want). Then we apply a transform of -30deg to get the angle in your example.
The image is a div with a border-radius and is positioned in the middle of the wrapper.
The css then makes use of keyframes to add an animation to the gap div to make it rotate when you hover over the wrapper. This gives the illusion of the circle rotating.
.wrapper {
position: relative;
height: 350px;
width: 350px;
}
.wrapper .circle {
position: absolute;
height: 340px;
width: 340px;
border: 5px solid #00C17F;
border-radius: 50%;
}
.wrapper .gap {
position: absolute;
width: 100px;
height: 350px;
left: 125px;
background: white;
-ms-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
.wrapper:hover .gap {
display: block;
-webkit-animation: rotateCircle 20s linear infinite;
-moz-animation: rotateCircle 20s linear infinite;
-ms-animation: rotateCircle 20s linear infinite;
-o-animation: rotateCircle 20s linear infinite;
animation: rotateCircle 20s linear infinite;
}
.wrapper .image {
position: absolute;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/f/f2/Light_Work_%28Unsplash%29.jpg");
background-size: cover;
background-position: right;
border-radius: 50%;
top: 10%;
left: 10%;
height: 80%;
width: 80%;
}
#keyframes rotateCircle {
from {
-ms-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-webkit-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
}
to {
-ms-transform: rotate(330deg);
-moz-transform: rotate(330deg);
-webkit-transform: rotate(330deg);
-o-transform: rotate(330deg);
transform: rotate(330deg);
}
}
<div class="wrapper">
<div class="circle"></div>
<div class="gap"></div>
<div class="image"></div>
</div>
You can have just one HTML element. But you need 3 layers:
holds the green circle
holds the image
creates the gaps by overwriting part of the circle
Layer 3 can also be made to rotate on hover.
CSS allows you to attach before and after pseudo elements to elements such as divs (not to normal img elements though, hence we use a div).
This way we have our 3 layers. We use the div itself to display the green circle and above it (in z-index terms) we place a pseudo element which creates the gaps by having a conic gradient background image. This only turns up when the user hovers. The other pseudo element holds the image with z-index set so it is above the others and doesn't get affected by the rotating conic gradient.
Note that all units used here are relative so the code is responsive.
.circle {
--gap: 30deg; /* set this to what you want the gap to be */
--border: 2px; /* set this to what you want the width of the green in the border to be can be in vmin for example for full responsiveness */
position: relative;
border: solid green var(--border);
border-radius: 50%;
width: 50vmin;
height: 50vmin;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.circle::before, .circle::after {
content: '';
border-radius: 50%;
position: absolute;
margin: 0;
padding: 0;
}
.circle::after {
/* position and center the image */
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
width: 70%;
height: 70%;
background-image: url(https://picsum.photos/id/0/400/400);
background-size: cover;
border-radius: 50%;
border-style: solid;
z-index: 2;
}
.circle:hover::before {
width: calc(100% + (3 * var(--border)));/* make it slightly bigger to make sure a 'stray' screen pixel does not get left out when the system converts part CSS px to screen pixels */
height: calc(100% + (3 * var(--border)));
top: calc(-1.5 * var(--border));
left: calc(-1.5 * var(--border));
z-index: 1;
background-image: conic-gradient(white 0deg, white var(--gap), transparent var(--gap), transparent 180deg, white 180deg, white calc(180deg + var(--gap)), transparent calc(180deg + var(--gap)), transparent 360deg);
animation: rotate 2s infinite linear;
}
#keyframes rotate {
to {
transform: rotate(360deg);
}
}
<div class="circle"></div>

Animate Blend Mode with opacity and transition

I'm looking for a way to change the opacity of background-color-blend-mode like
Photoshop. My goal is to animate the opacity of the blend-mode to make it disappear. Any ideas ?
#img-esadvalence {
background-image: url(http://leodurand.fr/works/planesad/esad1.jpg);
background-color: #e12a1c;
background-blend-mode: screen;
}
.all-img-menu {
background-size: contain;
background-position: center;
width: 110%;
padding-bottom: 40.75vh;
display: block;
top: 50%;
-ms-transform: translate(0%,-50%);
-webkit-transform: translate(0%,-50%);
transform: translate(0%,-50%);
position: absolute;
transition: all 0.6s ease;
}
<div id="img-esadvalence" class="all-img-menu"></div>
The blend mode only works when there are 2 backgrounds. To cancel the blend mode gradually, you can animate (transition) to a transparent background color.
Demo (hover the image to see the effect):
#img-esadvalence {
background-image: url(https://placeimg.com/640/480/animals);
background-color: #e12a1c;
background-blend-mode: screen;
transition: background-color 1s;
}
#img-esadvalence:hover {
background-color: transparent;
}
.all-img-menu {
background-size: contain;
background-position: center;
width: 110%;
padding-bottom: 40.75vh;
display: block;
top: 50%;
-ms-transform: translate(0%,-50%);
-webkit-transform: translate(0%,-50%);
transform: translate(0%,-50%);
position: absolute;
transition: all 0.6s ease;
}
<div id="img-esadvalence" class="all-img-menu"></div>

How to keep a diagonal running background animation without rotating the div?

I have created an animation where a background image moves from left to the right. I want this animation to go diagonal so I've turned the div 45 degrees using: -webkit-transform: rotate(45deg);
The result looks like this fiddle
As you can see, the div is turned (red border), but I want the div not to rotate. So how can I keep the diagonal animation without rotating the div?
Thanks
ps for demo purposes I've only used the -webkit- prefix
ps2 I can only modify one div with the css, so adding another div is
not possible
You can use pseudo elements to accomplish what you want:
html:
<div id='test'></div>
css:
#test:before
{
content: "";
position: absolute;
width: 200%;
height: 200%;
top: -50%;
left: -50%;
z-index: -1;
background: url(background.png) 0 0 repeat;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
background-image: url("http://www.easyvectors.com/assets/images/vectors/afbig/green-left-double-arrows-set-clip-art.jpg");
background-repeat: repeat;
-moz-animation: swim 2s linear 0s infinite;
-webkit-animation: swim 2s linear 0s infinite;
-webkit-transform: rotate(45deg);
}
#test {
position: relative;
overflow: hidden;
width: 300px;
height:300px;
border: 3px solid red;
}
#-webkit-keyframes swim {
from { background-position: 200% 0, 0 0; }
to { background-position: 100% 0, 0 0; }
}
Fiddle
Check out this great article by Craig Buckler for more information.

How to center this rotating image (CSS animation)

My CodePen: http://codepen.io/leongaban/pen/wJAip
The orange gear is 80x80 and so is the white # logo.
I added the blue background so you can see that for some reason the orange gear looks like it is spinning off center.
Here is the image lined up in photoshop:
html:
<div id="spinner">
<div id="logo">
<img src="http://leongaban.com/_codepen/whoat/loader-logo.png"/>
</div>
<div id="gear" class="spin">
<img src="http://leongaban.com/_codepen/whoat/loader-gear.png"/>
</div>
</div>
CSS:
div#spinner {
position: absolute;
width: 80px;
height: 80px;
top: 35%;
left: 50%;
margin-left: -40px;
background: blue;
}
div#logo {
position: absolute;
top: 0;
left: 0;
width: 80px;
height: 80px;
z-index: 3;
}
#logo img {
width: 100%;
height:100%;
}
div#gear {
position: absolute;
top: 0;
left: 0;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
pointer-events: none;
z-index: 2;
}
.spin {
-webkit-animation: rotation 4.5s linear infinite;
animation: rotation 4.5s linear infinite;
-webkit-transform: translateX(100%) translateY(-100%) rotate(45deg);
transform: translateX(100%) translateY(-100%) rotate(45deg);
}
Make the image in the #gear div block level.
#gear img{
display:block;
}
http://codepen.io/anon/pen/rjfbl
For whatever reason your gear element is getting a height of 84px. This will cause it to spin off-axis. As an experiment you might wish to try setting height and on #gear to something very small (e.g. 0px) and watching it; it will be as though it's rotating around a point at the top of its bounding box.
Set the width and height of your gear explicitly to 80x, or 100%, and it will work.
div#gear {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transition: -webkit-transform 0.1s;
transition: transform 0.1s;
pointer-events: none;
z-index: 2;
}
Codepen (yours with the two added lines, width and height): http://codepen.io/anon/pen/LuBvI

CSS3 Translate across an Arc

Is it at all possible with current CSS3 to translate an object (specifically a DIV) along an arc or curve? Here's an image to help illustrate.
You can use nested elements and make the wrapper and inner element rotate in opposite directions so that the rotation of the inner element compensates for the rotation of the wrapper.
If you don't need to keep the nested element horizontal, you can omit the inner rotation.
Here is a Dabblet. Stack Snippet:
/* Arc movement */
.wrapper {
width: 500px;
margin: 300px 0 0;
transition: all 1s;
transform-origin: 50% 50%;
}
.inner {
display: inline-block;
padding: 1em;
transition: transform 1s;
background: lime;
}
html:hover .wrapper {
transform: rotate(180deg);
}
html:hover .inner {
transform: rotate(-180deg);
}
<div class="wrapper">
<div class="inner">Hover me</div>
</div>
Also, Lea Verou wrote an article on this issue with a way that use only one element: http://lea.verou.me/2012/02/moving-an-element-along-a-circle/
Yes, that animation can be created using the transform-origin CSS3 property to set the rotation point in the far right so it moves like that.
Check it out: http://jsfiddle.net/Q9nGn/4/ (put your mouse over)
#c {
border: 1px solid black;
height: 400px;
}
#c:hover #m {
-webkit-transform: rotate(180deg);
-webkit-transition: all 1s ease-in-out;
-moz-transform: rotate(180deg);
-moz-transition: all 1s ease-in-out;
-o-transform: rotate(180deg);
-o-transition: all 1s ease-in-out;
-ms-transform: rotate(180deg);
-ms-transition: all 1s ease-in-out;
transform: rotate(180deg);
transition: all 1s ease-in-out;
}
#m {
width: 60px;
height: 60px;
position: absolute;
background: green;
border-radius: 30px;
top: 270px;
left: 20px;
-webkit-transform-origin:300px 30px;
-moz-transform-origin:300px 30px;
-o-transform-origin:300px 30px;
-ms-transform-origin:300px 30px;
transform-origin:300px 30px;
}
<div id="c">
<div id="m"></div>
</div>
An alternative to moving the transform origin, is to use a double nested element where an x-transform is applied to the outer container, and a y-transform with an appropriate easing curve is applied to the inner container.

Resources