This is our logo:
We would like to create it with css and animate the gear, but as you can see if you run my code, I am struggling with following:
Do you know how to solve this?
body{background: #fff;}
.parent{
display: flex;
height: 500px;
}
.gear{
position: relative;
width: 200px;
height: 200px;
margin: auto;
background: black;
border-radius: 50%;
animation-name: spin;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
.gear .center{
position: absolute;
top: 25px;
left: 25px;
z-index: 10;
width: 150px;
height: 150px;
background: #fff;
border-radius: 50%;
}
.tooth{
position: absolute;
top: -25px;
left: 75px;
z-index: 1;
width: 45px;
height: 250px;
background:black;
}
.tooth:nth-child(2){
transform: rotate(45deg);
}
.tooth:nth-child(3){
transform: rotate(90deg);
}
.tooth:nth-child(4){
transform: rotate(135deg);
}
@keyframes spin {
from {transform: rotate(0deg); }
to {transform: rotate(360deg);}
}
#heart {
position: relative;
width: 100px;
height: 90px;
}
#heart:before,
#heart:after {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 50px;
height: 80px;
background: #1D74BA;
-moz-border-radius: 50px 50px 0 0;
border-radius: 50px 50px 0 0;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 0 100%;
-moz-transform-origin: 0 100%;
-ms-transform-origin: 0 100%;
-o-transform-origin: 0 100%;
transform-origin: 0 100%;
}
#heart:after {
left: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 100% 100%;
-moz-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
-o-transform-origin: 100% 100%;
transform-origin :100% 100%;
}
svg.heart-rate{
position: absolute;
z-index:999;
transform: scale(0.6);
color:white;
fill: currentColor;
}
<div class="parent">
<div id="heart">
<svg class="heart-rate" ersion="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="150px" height="73px" viewBox="0 0 150 73" enable-background="new 0 0 150 73" xml:space="preserve">
<polyline fill="none" stroke="#009B9E" stroke-width="3" stroke-miterlimit="10" points="0,45.486 38.514,45.486 44.595,33.324 50.676,45.486 57.771,45.486 62.838,55.622 71.959,9 80.067,63.729 84.122,45.486 97.297,45.486 103.379,40.419 110.473,45.486 150,45.486"
/>
</svg>
</div>
<div class="gear">
<div class="center"></div>
<div class="tooth"></div>
<div class="tooth"></div>
<div class="tooth"></div>
<div class="tooth"></div>
</div>
</div>
CSS Shape. Hearts are complicated in real life but they're just two circles and a rotated square in CSS: We can draw that with a single element, thanks to the ::before and ::after pseudo elements. I <span class="heart"></span> you.
CSS animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.
Use position:absolute
on the heart and position it in the center of the parent using top
,left
and transform
body {
background: #fff;
}
.parent {
display: flex;
height: 500px;
position:relative;
}
.gear {
position: relative;
width: 200px;
height: 200px;
margin: auto;
background: black;
border-radius: 50%;
animation-name: spin;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
.gear .center {
position: absolute;
top: 25px;
left: 25px;
z-index: 10;
width: 150px;
height: 150px;
background: #fff;
border-radius: 50%;
}
.tooth {
position: absolute;
top: -25px;
left: 75px;
z-index: 1;
width: 45px;
height: 250px;
background: black;
}
.tooth:nth-child(2) {
transform: rotate(45deg);
}
.tooth:nth-child(3) {
transform: rotate(90deg);
}
.tooth:nth-child(4) {
transform: rotate(135deg);
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#heart {
position: absolute;
width: 100px;
height: 90px;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 9999;
margin-top:10px;
}
#heart:before,
#heart:after {
position: absolute;
content: "";
left: 50px;
top: 0;
width: 50px;
height: 80px;
background: #1D74BA;
-moz-border-radius: 50px 50px 0 0;
border-radius: 50px 50px 0 0;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 0 100%;
-moz-transform-origin: 0 100%;
-ms-transform-origin: 0 100%;
-o-transform-origin: 0 100%;
transform-origin: 0 100%;
}
#heart:after {
left: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin: 100% 100%;
-moz-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
-o-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
svg.heart-rate {
position: absolute;
z-index: 999;
color: white;
fill: currentColor;
left: 50%;
top: 40%;
transform: translate(-50%,-50%) scale(0.6);
}
<div class="parent">
<div id="heart">
<svg class="heart-rate" ersion="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="150px" height="73px" viewBox="0 0 150 73" enable-background="new 0 0 150 73" xml:space="preserve">
<polyline fill="none" stroke="#fff" stroke-width="3" stroke-miterlimit="10" points="0,45.486 38.514,45.486 44.595,33.324 50.676,45.486 57.771,45.486 62.838,55.622 71.959,9 80.067,63.729 84.122,45.486 97.297,45.486 103.379,40.419 110.473,45.486 150,45.486"
/>
</svg>
</div>
<div class="gear">
<div class="center"></div>
<div class="tooth"></div>
<div class="tooth"></div>
<div class="tooth"></div>
<div class="tooth"></div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With