Box-shadow is being cut off of the image - html

The image should look like this.
box-shadow added to the code:
Image
Instead, it is looking like this and I don't know why and how to fix it. Image
You can see the box-shadow is being cut off of the image on all 4 sides.
How do I fix it so that the image isn't being cut off?
Code: https://jsfiddle.net/8mgvn40u/
.curtain {
width: 550px;
height: 250px;
border-radius: 20px;
position: relative;
overflow: hidden;
background: #000000;
box-sizing: border-box;
}
.jacketa {
position: absolute;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 180px;
height: 180px;
margin: auto;
border-radius: 50%;
transition: 0.5s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 .jacketa {
right: 0;
left: auto;
}
.curtain:hover .j1 {
transform: translateX(-500%);
}
.curtain:hover .j2 {
transform: translateX(500%);
}
<div class="curtain">
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>

Because of overflow, bow-shadow gets cut-off (already said) , You could also use transform to easily keep the shadows within the visible area.
increase first the hidden overflow area then decrease what stands inside. smaller it won't get clipped anymore.
example of the idea with a short fixed involving : transform:scale(1.1)VS transform:scale(0.9) to keep a close ratio of the initial layout size.
.curtain {
width: 550px;
height: 250px;
border-radius: 20px;
position: relative;
overflow: hidden;
background: #000000;
box-sizing: border-box;
}
.split-wrap{
transform:scale(1.1);
}
.jacketa {
position: absolute;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
transform:scale(0.9);
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 180px;
height: 180px;
margin: auto;
border-radius: 50%;
transition: 0.5s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 .jacketa {
right: 0;
left: auto;
}
.curtain:hover .j1 {
transform: translateX(-500%);
}
.curtain:hover .j2 {
transform: translateX(500%);
}
<div class="curtain">
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>

that happening because you gave overflow: hidden to .j1 and .j2, changing it into overflow: visible will fix the box-shadow issue but will mess up your curtain animation.
alternatively you can make .j1 and .j2 bigger but with padding so the box-shadow won't overlap it.

Related

Setting a time for how long it will take for a transition to finish

I'm confused about how the transition property works.
Does transition time mean actual time?
For example:
.panel-left,
.panel-right {
transition: all ease 30s;
]
You click on the play image and both sides open.
How come the 2 sides are open in less than 30 seconds?
Would I be using a different transition property to do that?
Would it be done a different way?
code https://jsfiddle.net/bfjcn4xk/
What would be the css property to use to set a time for how long it will take for the 2 sides to be fully open?
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 30s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100vw);
}
.curtain.slide .panel-right {
transform: translateX(100vw);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
display: block !important;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 180px;
height: 180px;
margin: auto;
border-radius: 50%;
box-shadow: 0 0 20px 2px #f9066bf7;
transition: 5s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 5s ease;
}
.j2 .jacketa {
right: 0;
left: auto;
}
.curtain.slide .split-wrap {
box-shadow: 0 0 20px 2px rgba(249, 6, 167, 0);
}
.container {
height: auto;
}
.curtain.slide .j1 {
transform: translateX(-100vw);
}
.curtain.slide .j2 {
transform: translateX(100vw);
}
.container {
width: 990px;
height: 1530px;
margin: 100px auto;
padding: 25px;
overflow: hidden;
border-radius: 25px;
border: 2px solid #0059dd;
box-sizing: border-box;
background: #000000;
}
.container-top {
position: relative;
height: 310px;
margin: 0 0 45px 0;
border-radius: 25px;
border: 3px solid #0059dd;
box-sizing: border-box;
background: url("https://i.imgur.com/jEMIULl.jpg") no-repeat 0 0;
background-size: cover;
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>
Each of the two panels has width 50%. But to open them the CSS translates them by -100vw and 100vw respectively.
So, basically, they are moved further to the left and right than they need to be - they have disappeared from view before the transition time is up.
Try this experiment: change one of the panels translation to 100% - that means 100% of its width, not the container or the viewport's width. You will see that the right panel moves at about half the speed of the left one, it takes 30 seconds to get out of view.
.curtain.slide .panel-left {
transform: translateX(-100vw);
}
.curtain.slide .panel-right {
transform: translateX(100%);/* CHANGED */
}
I'm not sure why the code would have been written to translate in 100vw terms - 'normally' I would have translated an element its full (100%) width to get it out of view. Then it is very clear that the transition time is the time the element will take to disappear. So, either change your HTML to do as above, or reduce your transition time.

CSS animated SVG disappears when container gets too small

I have create a CSS animation. For the most part, it works as expected.
You can find and test it here: (The weird colors are only for testing...)
https://jsfiddle.net/ec3j8k0r/5/
.svgContainer
{
position: relative;
/*display: inline-block;*/
height: 150px;
width: 150px;
background-color: red;
color: white;
}
.svgCircleBig
{
position:absolute;
/*display: inline-block;*/
height: 100%;
width: 100%;
background-color: transparent;
}
.svgCircleMedium
{
/*display: inline-block;*/
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: forestgreen;
}
.svgCircleSmall
{
/*display: inline-block;*/
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: blue;
}
.svgColor
{
fill: white;
stroke: white;
stroke-miterlimit: 1;
}
#-webkit-keyframes rotateRightKeyFrames
{
from
{
-webkit-transform: rotate(0deg);
}
to
{
-webkit-transform: rotate(360deg);
}
}
.rotateRight
{
-webkit-animation: rotateRightKeyFrames 3s linear infinite;
}
.rotateRightFast
{
-webkit-animation: rotateRightKeyFrames 4s linear infinite;
}
#-webkit-keyframes rotateLeftKeyFrames
{
from
{
-webkit-transform: rotate(360deg);
}
to
{
-webkit-transform: rotate(0deg);
}
}
.rotateLeft
{
-webkit-animation: rotateLeftKeyFrames 2s linear infinite;
}
<div class="svgContainer">
<div class="svgCircleBig">
<svg class="rotateRight" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleMedium">
<svg class="rotateLeft" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleSmall">
<svg class="rotateRightFast" viewBox="0 0 90 90">
<use xlink:href="#gear"/>
</svg>
</div>
</div>
</div>
</div>
<div style="visibility:collapse; display:none;">
<svg viewBox="0 0 90 90">
<g id="gear"><path class="svgColor" d="M90,46.6v-4l-6.2-2.4c-.2-1.6-.5-3.2-.8-4.7l5-4.4a23.49,23.49,0,0,0-1.4-3.7l-6.7-.2a33.76,33.76,0,0,0-2.4-4.1l3.2-5.8a36.12,36.12,0,0,0-2.5-3l-6.3,2.1c-1.2-1.1-2.4-2.1-3.7-3.1l1-6.6a37.91,37.91,0,0,0-3.4-2L60.6,8.9a40.38,40.38,0,0,0-4.5-1.6L54.8.8C53.5.5,52.2.3,50.9.1L47.4,5.8A9.74,9.74,0,0,0,45,5.6a19.27,19.27,0,0,0-2.4.1L39.1,0c-1.3.2-2.6.4-3.9.7L33.9,7.2c-1.5.5-3,1-4.5,1.6L24.2,4.6a37.91,37.91,0,0,0-3.4,2l1,6.6c-1.3,1-2.5,2-3.7,3.1l-6.3-2.1c-.9,1-1.7,2-2.5,3L12.5,23a33.76,33.76,0,0,0-2.4,4.1l-6.7.2c-.5,1.2-1,2.4-1.4,3.7l5,4.4a35.45,35.45,0,0,0-.8,4.7L0,42.6v4L6.2,49c.2,1.6.5,3.2.8,4.7L2,58.1a23.49,23.49,0,0,0,1.4,3.7l6.7.2a33.76,33.76,0,0,0,2.4,4.1L9.3,71.9a36.12,36.12,0,0,0,2.5,3l6.3-2.1c1.2,1.1,2.4,2.1,3.7,3.1l-1,6.6a37.91,37.91,0,0,0,3.4,2l5.2-4.2a40.38,40.38,0,0,0,4.5,1.6l1.3,6.5c1.3.3,2.6.5,3.9.7l3.5-5.7c.8,0,1.6.1,2.4.1a19.27,19.27,0,0,0,2.4-.1l3.5,5.7c1.3-.2,2.6-.4,3.9-.7l1.3-6.5c1.5-.5,3-1,4.5-1.6l5.2,4.2a37.91,37.91,0,0,0,3.4-2l-1-6.6c1.3-1,2.5-2,3.7-3.1l6.3,2.1c.9-1,1.7-2,2.5-3l-3.2-5.8A33.76,33.76,0,0,0,79.9,62l6.7-.2c.5-1.2,1-2.4,1.4-3.7l-5-4.4a35.45,35.45,0,0,0,.8-4.7ZM45,78.7A34.1,34.1,0,1,1,79.1,44.6,34.14,34.14,0,0,1,45,78.7Z" /></g>
</svg>
</div>
My problem: If the svgContainer class gets too small, let's say only 30px, the most inner animation, with the blue background, disappears to the bottom.
.svgContainer
{
position: relative;
/*display: inline-block;*/
height: 30px;
width: 30px;
background-color: red;
color: white;
}
You can see it live, when changing the CSS code in the fiddle.
My question: Can somebody see what the problem is?
Add display:block to all your SVG elements:
svg {
display:block;
}
.svgContainer {
position: relative;
height: 30px;
width: 30px;
background-color: red;
color: white;
}
.svgCircleBig {
position: absolute;
height: 100%;
width: 100%;
background-color: transparent;
}
.svgCircleMedium {
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: forestgreen;
}
.svgCircleSmall {
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: blue;
}
.svgColor {
fill: white;
stroke: white;
stroke-miterlimit: 1;
}
#-webkit-keyframes rotateRightKeyFrames {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
.rotateRight {
-webkit-animation: rotateRightKeyFrames 3s linear infinite;
}
.rotateRightFast {
-webkit-animation: rotateRightKeyFrames 4s linear infinite;
}
#-webkit-keyframes rotateLeftKeyFrames {
from {
-webkit-transform: rotate(360deg);
}
to {
-webkit-transform: rotate(0deg);
}
}
.rotateLeft {
-webkit-animation: rotateLeftKeyFrames 2s linear infinite;
}
<div class="svgContainer">
<div class="svgCircleBig">
<svg class="rotateRight" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleMedium">
<svg class="rotateLeft" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleSmall">
<svg class="rotateRightFast" viewBox="0 0 90 90">
<use xlink:href="#gear"/>
</svg>
</div>
</div>
</div>
</div>
<div style="visibility:collapse; display:none;">
<svg viewBox="0 0 90 90">
<g id="gear"><path class="svgColor" d="M90,46.6v-4l-6.2-2.4c-.2-1.6-.5-3.2-.8-4.7l5-4.4a23.49,23.49,0,0,0-1.4-3.7l-6.7-.2a33.76,33.76,0,0,0-2.4-4.1l3.2-5.8a36.12,36.12,0,0,0-2.5-3l-6.3,2.1c-1.2-1.1-2.4-2.1-3.7-3.1l1-6.6a37.91,37.91,0,0,0-3.4-2L60.6,8.9a40.38,40.38,0,0,0-4.5-1.6L54.8.8C53.5.5,52.2.3,50.9.1L47.4,5.8A9.74,9.74,0,0,0,45,5.6a19.27,19.27,0,0,0-2.4.1L39.1,0c-1.3.2-2.6.4-3.9.7L33.9,7.2c-1.5.5-3,1-4.5,1.6L24.2,4.6a37.91,37.91,0,0,0-3.4,2l1,6.6c-1.3,1-2.5,2-3.7,3.1l-6.3-2.1c-.9,1-1.7,2-2.5,3L12.5,23a33.76,33.76,0,0,0-2.4,4.1l-6.7.2c-.5,1.2-1,2.4-1.4,3.7l5,4.4a35.45,35.45,0,0,0-.8,4.7L0,42.6v4L6.2,49c.2,1.6.5,3.2.8,4.7L2,58.1a23.49,23.49,0,0,0,1.4,3.7l6.7.2a33.76,33.76,0,0,0,2.4,4.1L9.3,71.9a36.12,36.12,0,0,0,2.5,3l6.3-2.1c1.2,1.1,2.4,2.1,3.7,3.1l-1,6.6a37.91,37.91,0,0,0,3.4,2l5.2-4.2a40.38,40.38,0,0,0,4.5,1.6l1.3,6.5c1.3.3,2.6.5,3.9.7l3.5-5.7c.8,0,1.6.1,2.4.1a19.27,19.27,0,0,0,2.4-.1l3.5,5.7c1.3-.2,2.6-.4,3.9-.7l1.3-6.5c1.5-.5,3-1,4.5-1.6l5.2,4.2a37.91,37.91,0,0,0,3.4-2l-1-6.6c1.3-1,2.5-2,3.7-3.1l6.3,2.1c.9-1,1.7-2,2.5-3l-3.2-5.8A33.76,33.76,0,0,0,79.9,62l6.7-.2c.5-1.2,1-2.4,1.4-3.7l-5-4.4a35.45,35.45,0,0,0,.8-4.7ZM45,78.7A34.1,34.1,0,1,1,79.1,44.6,34.14,34.14,0,0,1,45,78.7Z" /></g>
</svg>
</div>

Masking an object to make it appear as if it goes behind the item it's rotating around

I'm trying to make a 'dot' orbit around another object (circle) but due to the z-index the dot always appears above the circle it is meant orbiting around.
CodePen link: https://codepen.io/moy/pen/ROVZXd?editors=1100
Ideally the 2nd half of the animation would take place behind the object so it's not seen until it comes out the other side - is that possible?
I thought about fading out the object that is moving around but I don't think that would give a smooth/masked effect?
A bit stuck as to how I'd mask this area as I can't see a way the CSS would know it's meant to be hidden. I thought maybe I could change the z-index 50% though the animation it and reset it at 0%/100% but that doesn't appear to do anything.
Any ideas? Thanks in advance!
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 30px auto;
position: relative;
width: 100px;
z-index: 20;
}
.orbit {
border: 2px #eee transparent;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
z-index: 10;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
z-index: 10;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg); z-index: 20;
}
50% {
z-index: -20;
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg); z-index: 20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
I seem to have solved this by adding a negative z-index to an animation applied to the parent .orbit
Link: https://codepen.io/moy/pen/wZdpRw?editors=1100
I initially applied this at 50% through the animation as that should be the furthest away the dot is before it comes back behind the larger circle. However this didn't work, setting it on 100% did work. Not entirely sure why but it seems to work!
The initial issue was due to the fact that you are applying z-index to the parent element and doing so it will impossible to make the child to move behind it (Why elements with any z-index value can never cover its child?) thus changin z-index is useless
Even if you remove the z-index from the parent you still have the transform that is also creating a stacking context making impossible to the child element to move behind so you cannot make the .moon to move behind the .earth.
The only way to do it (like you already noticed) is to remove z-index from the .earth to avoid the earth creating a stacking context and animate z-index of orbit to make the orbit AND the moon moving behind the earth (not only the moon).
Add some coloration to better see this:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 60px auto;
position: relative;
width: 100px;
}
.orbit {
animation: hide ease-in-out infinite;
animation-duration: 2s;
background:red;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg);
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg);
}
}
#keyframes hide {
0% {
z-index: 20;
}
100% {
z-index: -20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
Now if you add back z-index to earth it will stop working because of the stacking context:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 60px auto;
position: relative;
width: 100px;
z-index:2;
}
.orbit {
animation: hide ease-in-out infinite;
animation-duration: 2s;
background:red;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg);
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg);
}
}
#keyframes hide {
0% {
z-index: 20;
}
100% {
z-index: -20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
You can try key-framing the opacity:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 30px auto;
position: relative;
width: 100px;
z-index: 20;
}
.orbit {
border: 2px #eee transparent;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
z-index: 10;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
z-index: 10;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg); opacity: 1;
}
56% {
opacity: 1;
}
58% {
opacity: 0;
}
77% {
opacity: 0;
}
78% {
opacity: 1;
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg); opacity: 1;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>

Button border on hover moves the text inside

I have created a border-like keyframe CSS style. When I hover the button the border-like animation should start from top-right to top-left then to bottom-left then after to bottom-right and finally to top-right again. When I hover the button the previous sequence should happen and is already created. However; when hovered, the text inside the button moves, which makes the button looks weird.
I looked at the answer to this question, but it's not applicable in my case as I am not using border styling on hover. Instead, I am changing the background color, width, and height of the three spans, not borders.
How can I prevent this shake with the method the animation is created?
CodePen: https://codepen.io/Tes3awy/pen/ZZRpBW
HTML
<div class="wrapper">
<a class="custom-btn" href="https://mince.34way.com/about/" title="About">
About Us
<span class="border-top"></span>
<span class="border-right"></span>
<span class="border-bottom"></span>
<span class="border-left"></span>
</a>
</div>
CSS
body {
position: relative;
height: 100vh;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.custom-btn {
position: relative;
width: 183px;
height: 55px;
line-height: 55px;
display: inline-block;
text-align: center;
text-transform: uppercase;
margin: 0 auto;
border: 2px solid #77a942;
color: #77a942;
text-decoration: none;
}
span[class^="border-"] {
opacity: 0;
}
.border-top {
position: absolute;
top: -2px;
right: 0;
width: 100%;
height: 3px;
background-color: transparent;
}
.border-left {
position: absolute;
top: 0;
left: -2px;
width: 3px;
height: 100%;
background-color: transparent;
}
.border-bottom {
position: absolute;
left: 0;
bottom: -2px;
width: 100%;
height: 3px;
background-color: transparent;
}
.border-right {
position: absolute;
bottom: 0;
right: -2px;
width: 3px;
height: 100%;
background-color: transparent;
}
.custom-btn:hover .border-top {
animation: animateTop .2s 1 alternate ease forwards;
}
.custom-btn:hover .border-left {
animation: animateLeft .2s 1 alternate ease forwards;
animation-delay: .2s;
}
.custom-btn:hover .border-bottom {
animation: animateBottom .2s 1 alternate ease forwards;
animation-delay: .4s;
}
.custom-btn:hover .border-right {
animation: animateRight .2s 1 alternate ease forwards;
animation-delay: .6s;
}
#keyframes animateTop {
0% {
width: 0;
height: 0;
opacity: 0;
background-color: #77a942;
}
50% {
width: 50%;
height: 3px;
opacity: 1;
background-color: #77a942;
}
100% {
width: 100%;
height: 3px;
opacity: 1;
background-color: #77a942;
}
}
#keyframes animateLeft {
0% {
width: 0;
height: 0;
opacity: 0;
background-color: #77a942;
}
50% {
width: 3px;
height: 50%;
opacity: 1;
background-color: #77a942;
}
100% {
width: 3px;
height: 100%;
opacity: 1;
background-color: #77a942;
}
}
#keyframes animateBottom {
0% {
width: 0;
height: 0;
opacity: 0;
background-color:#77a942;
}
50% {
width: 50%;
height: 3px;
opacity: 1;
background-color:#77a942;
}
100% {
width: 100%;
height: 3px;
opacity: 1;
background-color:#77a942;
}
}
#keyframes animateRight {
0% {
width: 0;
height: 0;
opacity: 0;
background-color: #77a942;
}
50% {
width: 3px;
height: 50%;
opacity: 1;
background-color: #77a942;
}
100% {
width: 3px;
height: 100%;
opacity: 1;
background-color: #77a942;
}
}
When you translate things by 50%, they may end up in-between pixels. When you use a transition, CSS tends to change its mind on what pixel it rounds to. Try to make sure that the button you're centering text in has height/width that CSS has a definite position it can settle on when you divide it by half.

css only half text box is showing?

Just got this search button from codepen, Tried placing it in my website and boom, Doesn't work! I've had a mess around and i can't see what the issue is,
What happens is the animations plays lovely! The search bar loads, But when typing, You can only see half the text, See image below
Heres my code
$brand: #b3c33a;
$speed: 0.5s;
body {
color: $brand;
background-color: #333;
}
.search {
position: absolute;
top: 50%;
left: 50%;
margin-left: -300px;
width: 600px;
}
svg {
position: absolute;
transform: translateX(-246px);
width: 600px;
height: auto;
stroke-width: 8px;
stroke: $brand;
stroke-width: 1px;
stroke-dashoffset: 0;
stroke-dasharray: 64.6 206.305;
transition: all 0.5s ease-in-out;
stroke-linejoin: round;
stroke-linecap: round;
}
.input-search {
position: absolute;
width: calc(100% - 148px);
height: 64px;
top: 0;
right: 20px;
bottom: 0;
left: 0;
border: none;
background-color: transparent;
outline: none;
padding: 20px;
font-size: 50px;
}
.search-label {
position: absolute;
display: block;
width: 108px;
height: 108px;
top: 0;
left: 50%;
margin-left: -54px;
z-index: 100;
transition: $speed ease-in-out;
}
.isActive {
.search-label {
transform: translateX(246px);
}
svg {
stroke-dashoffset: -65;
stroke-dasharray: 141.305 65;
transform: translateX(0);
}
&.full svg {
stroke-dashoffset: -65;
stroke-dasharray: 141.305 65;
transform: translateX(0);
}
}
.full {
.search-label {
transform: translateX(246px);
}
svg {
stroke-dashoffset: 0;
stroke-dasharray: 64.6 206.305;
transform: translateX(0);
}
}
<div class="col-md-10">
<div class="search">
<svg version="1.1" viewBox="0 0 142.358 24.582">
<path id="search-path" fill="none" d="M131.597,14.529c-1.487,1.487-3.542,2.407-5.811,2.407
c-4.539,0-8.218-3.679-8.218-8.218s3.679-8.218,8.218-8.218c4.539,0,8.218,3.679,8.218,8.218
C134.004,10.987,133.084,13.042,131.597,14.529c0,0,9.554,9.554,9.554,9.554H0"/>
</svg>
<label for="search" class="search-label"></label>
<input type="search" id="search" autocomplete="off" class="input-search"/>
</div>
<script type="text/javascript">
/*
Inspired by Dribble "Search..."
By: Anish Chandran
Link: http://drbl.in/nRxe
*/
var searchField = $('.search');
var searchInput = $("input[type='search']");
var checkSearch = function(){
var contents = searchInput.val();
if(contents.length !== 0){
searchField.addClass('full');
} else {
searchField.removeClass('full');
}
};
$("input[type='search']").focus(function(){
searchField.addClass('isActive');
}).blur(function(){
searchField.removeClass('isActive');
checkSearch();
});
</script>
</div>
CSS Only (not scss)
body {
color: #b3c33a;
background-color: #333;
}
.search {
position: absolute;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -54px;
width: 600px;
}
svg {
position: absolute;
transform: translateX(-246px);
width: 600px;
height: auto;
stroke-width: 8px;
stroke: #b3c33a;
stroke-width: 1px;
stroke-dashoffset: 0;
stroke-dasharray: 64.6 206.305;
transition: all 0.5s ease-in-out;
stroke-linejoin: round;
stroke-linecap: round;
}
.input-search {
position: absolute;
width: calc(100% - 148px);
height: 64px;
top: 0;
right: 20px;
bottom: 0;
left: 0;
border: none;
background-color: transparent;
outline: none;
padding: 20px;
font-size: 50px;
}
.search-label {
position: absolute;
display: block;
width: 108px;
height: 108px;
top: 0;
left: 50%;
margin-left: -54px;
z-index: 100;
transition: 0.5s ease-in-out;
}
.isActive .search-label {
transform: translateX(246px);
}
.isActive svg {
stroke-dashoffset: -65;
stroke-dasharray: 141.305 65;
transform: translateX(0);
}
.isActive.full svg {
stroke-dashoffset: -65;
stroke-dasharray: 141.305 65;
transform: translateX(0);
}
.full .search-label {
transform: translateX(246px);
}
.full svg {
stroke-dashoffset: 0;
stroke-dasharray: 64.6 206.305;
transform: translateX(0);
}
That's not pure CSS, so wouldn't output correctly in your browser. They used SASS (http://sass-lang.com/), so you would need to compile the SASS to CSS first if you want to use it, or look for the pure CSS output (Which should be available if you copied it from Codepen)