SVG Rotating Dashed Circle Border on Hover - html
I am trying to create an SVG Hover Animation Effect using CSS.
What I want to do attain is that when I hover on my Icon the solid circle container will rotate with a dashed container. See image below.
Check out what I have done so far: http://jsfiddle.net/uhkwLuph/3/
So far here's my code.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="200px"
height="200px" viewBox="0 0 200 200" style="enable-background:new 0 0 200 200;" xml:space="preserve" id="icon">
<style type="text/css">
.st0
{
fill:none;
stroke:#F2F2F2;
stroke-width:4;
stroke-miterlimit:10;
}
#icon .st0{
-webkit-transition: .5s;
}
#icon:hover .st0{
fill: #ffffff;
stroke: #1f8a4c;
cursor: pointer;
}
</style>
<g id="container">
<circle class="st0" cx="101" cy="99" r="89.333"/>
</g>
<g id="icon-details">
<path class="st0" d="M146.899,134.202c3.856,4.702,2.772,11.963-2.418,16.218l0,0c-5.192,4.258-12.523,3.896-16.38-0.806
l-30.004-36.594c-3.855-4.701-2.772-11.964,2.418-16.22l0,0c5.19-4.256,12.523-3.895,16.377,0.808L146.899,134.202z"/>
<circle class="st0" cx="77.843" cy="72.434" r="33.331"/>
<circle class="st0" cx="77.844" cy="72.434" r="22.343"/>
</g>
</svg>
I understand that it can be attain with stroke-dasharray and stroke-offset + #Keyframes (CSS) but can anyone point me how we can implement it?
Here's the JSFIDDLE:
Fiddle: Click
Now you just have to play with the dashoffset/dasharray values.
CSS:
body { background: #27ae60; }
#container{
}
#container:hover circle{
animation: dash 2s linear forwards;
-webkit-animation: dash 2s linear forwards;
}
#keyframes dash {
0%{ stroke-dashoffset:0;
stroke-dasharray:0;}
100% {
stroke-dashoffset:10;
stroke-dasharray:180;
}
}
#-webkit-keyframes dash {
0%{ stroke-dashoffset:0;
stroke-dasharray:0;}
100% {
stroke-dashoffset:10;
stroke-dasharray:180;
}
}
UPDATE
:root { background: #27ae60; transition: background .3s ease}
[class=loop]{
position:relative;
margin: 240px auto
}
[class=loop], [class=circle]{
width: 240px;
height: 240px
}
[class=loop]:before, [class=loop]:after{
content: '';
z-index: 1
}
[class=loop]:before, [class=loop]:after,[class=circle]{
position: absolute;
}
[class=loop]:after,[class=circle]{
border-radius: 50%
}
[class=loop]:before{
width: 80px;
height: 20px;
border-radius: 10px;
border: 4px solid green;
transform: rotateZ(50deg);
top: 160px;
left: 114px
}
[class=loop]:after{
top: 32px;
left: 32px;
width: 100px;
height: 100px;
border: 10px solid transparent;
box-shadow: inset 0 0 0 4px green,0 0 0 4px green
}
[class=circle]{
border: 4px dashed green;
top: 0px;
left: 0px;
background: white;
z-index: 0;
background-clip: content-box
}
[class=loop]:hover [class=circle]{
-webkit-animation: spin 1s infinite linear;
-moz-animation: spin 1s infinite linear;
animation: spin 1s infinite linear
}
#-webkit-keyframes spin {
to { transform: rotate(360deg); }
}
#-moz-keyframes spin {
to { transform: rotate(360deg); }
}
#keyframes spin {
to { transform: rotate(360deg); }
}
<div class=loop>
<div class=circle></div>
</div>
Single element solution would be
:root { background: #27ae60; transition: background .3s ease}
:root:hover { background: red }
div{
width: 80px;
height: 20px;
border-radius: 10px;
border: 4px solid white;
transform: rotateZ(45deg);
margin: 230px auto;
position: relative
}
div:before,div:after{
content: '';
position: absolute;
border-radius: 50%
}
div:before{
width: 100px;
height: 100px;
border: 10px solid transparent;
top: -52px;
left: -124px;
box-shadow: inset 0 0 0 4px white,0 0 0 4px white
}
div:after{
width: 250px;
height: 250px;
border: 4px dashed white;
top: -124px;
left: -154px
}
div:hover:after{
-webkit-animation: spin 1s infinite linear;
-moz-animation: spin 1s infinite linear;
animation: spin 1s infinite linear;
}
#-webkit-keyframes spin {
to { transform: rotate(360deg); }
}
#-moz-keyframes spin {
to { transform: rotate(360deg); }
}
#keyframes spin {
to { transform: rotate(360deg); }
}
<div/>
Related
Reversing CSS animation after leaving hover does not work
I'm trying to reverse the animation after the user is not hovering. I tried making a keyframe with the opposite animation, using reverse and adding transition: all 2s but neither worked. I also tried div::after:not(:hover). html { background-color: black; } div { position: relative; width: 50vw; transition: all 2s reverse; } div:hover::after { position: absolute; content: " "; height: 50px; width: 50px; top: 50%; right: 0; border: solid rgb(255, 255, 255); border-width: 0 10px 10px 0; display: inline-block; animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards; // background-color: green; } div::after:not(:hover) { animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) reverse; } #keyframes fadeMain { from { opacity: 0; transform: translateX(0px) rotate(-45deg); } to { opacity: 1; transform: translateX(20px) rotate(-45deg); } } // Doesnt work: // #keyframes fadeMainOut { // from { // opacity: 1; // transform: translateX(20px) rotate(-45deg); // } // to { // opacity: 0; // transform: translateX(0px) rotate(-45deg); // } // } <div> <svg id="centerLogo" width="586" height="192" viewBox="0 0 586 192" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M0 192H36.5324L97.2281 82.4505L79.1057 49.2973L0 192ZM124.555 32.8649L106.145 3.43666e-05L88.023 32.8649L106.145 65.7298L176.046 192H212.291L124.555 32.8649Z" fill="white"/> <path d="M332.66 92.8289L335.248 89.6577L400.547 0.576604H366.315L318.277 66.3063L315.688 69.7658L313.099 66.3063L264.773 0.576604H230.541L296.127 89.6577L298.428 92.8289V93.1171L315.688 116.18L371.493 192H405.724L332.66 92.8289ZM225.651 192H259.882L307.058 128L290.086 104.649L225.651 192Z" fill="white"/> <path d="M551.769 3.43666e-05L498.552 72.6487V72.937L445.623 3.43666e-05H411.392L479.567 93.4054L481.58 96V96.2883L485.032 100.901V192H512.36V100.613L513.223 99.7478L515.812 96.2883V96L517.825 93.4054L586 3.43666e-05H551.769Z" fill="white"/> </svg> </div>
Your problem is that div::after:not(:hover) doesn't render an :after element in div. Also to switch animation between hover and non hover you need to use keywords other than from to. these changes should fix it div::after { content: " "; position: absolute; height: 50px; width: 50px; top: 50%; right: 0; border: solid rgb(255, 255, 255); border-width: 0 10px 10px 0; display: inline-block; opacity: 0; animation: fadeMainOut 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards; } div:hover::after { content: " "; position: absolute; height: 50px; width: 50px; top: 50%; right: 0; border: solid rgb(255, 255, 255); border-width: 0 10px 10px 0; display: inline-block; animation: fadeMain 2s cubic-bezier(0.785, 0.135, 0.15, 0.86) forwards; } #keyframes fadeMain { from { opacity: 0; transform: translateX(0px) rotate(-45deg); } to { opacity: 1; transform: translateX(20px) rotate(-45deg); } } #keyframes fadeMainOut { 0% { opacity: 1; transform: translateX(20px) rotate(-45deg); } 100% { opacity: 0; transform: translateX(0px) rotate(-45deg); } }
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>
CSS animation on mac vs windows
I'm trying to create a spinner animation but i've encountered some issues with the difference between windows and mac displays. The animation is a pretty basic circular spinner created with html and css <div class="cow-spinner"> <span></span> <span></span> <span></span> <span></span> </div> and some basic css: .cow-spinner { display: inline-block; position: relative; width: 64px; height: 64px; } .cow-spinner span { box-sizing: border-box; display: block; position: absolute; width: 51px; height: 51px; margin: 6px; border: 3px solid black; border-radius: 50%; animation: cow-spin 1.2s ease-in-out infinite; border-color: black transparent transparent transparent; } .cow-spinner span:nth-child(1) { animation-delay: -0.45s; } .cow-spinner span:nth-child(2) { animation-delay: -0.3s; } .cow-spinner span:nth-child(3) { animation-delay: -0.15s; } #keyframes cow-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } The animation itself works perfectly, with a working example here: https://codepen.io/fatoilyguy/pen/oaZMMp My issue is that on mac the circle itself has smooth edges with consistent width like so: but on windows, the circle is pixelated and has weird width variations: From what I can see, there is no difference between browsers on either platform. Is there any way i could prevent this difference from happening between platforms?
You could try a SVG approach and check if the rendering it's good everywhere .loader { display: inline-block; height: 100px; width: 100px; transform: rotateZ(0deg); animation: rotate 1.5s linear infinite; } svg { max-width: 140px; max-height: 140px; fill: none; stroke: #9bc; stroke-width: 5px; stroke-dasharray: 301px; stroke-dashoffset: 200px; animation: path 1.5s linear 0s infinite; } #keyframes path { 60% { stroke-dashoffset: 40px; } 100% { stroke-dashoffset: 200px; } } #keyframes rotate { 100% { transform: rotateZ(360deg) } } <div class="loader"> <svg viewport="0 0 100 100" preserveAspectRatio="xMidYMid meet"> <path d="M 50, 50 m -48, 0 a 48,48 0 1,0 96,0 a 48,48 0 1,0 -96,0" /> </svg> </div>
CSS3 : appear check mark and text on the same time
I have a button with check mark and text.I want check mark and text to be appeared on the same time. in my code I get text to be appeared early than check mark. .sending_btn { outline: none; width: 128px; height: 30px; border-radius: 2px; border: thin #3a3f51 solid; transform-origin: center center; } .sending_btn span { color: #3a3f51; } .sending_btn:focus, .sending_btn:active { padding: 0; } svg{ vertical-align:middle; } .svg-success { stroke-width: 2px; stroke: #3a3f51; fill: none; } .svg-success path { stroke-dasharray: 17px, 17px; stroke-dashoffset: 0px; -webkit-animation: checkmark 0.25s ease-in-out 0.2s backwards; animation: checkmark 0.25s ease-in-out 0.2s backwards; } .svg-success circle { stroke-dasharray: 76px, 76px; stroke-dashoffset: 0px; transform: rotate(-90deg); transform-origin: 50% 50%; -webkit-animation: checkmark-circle 0.6s ease-in-out forwards; animation: checkmark-circle 0.6s ease-in-out forwards; } #keyframes checkmark { 0% { stroke-dashoffset: 17px; } 100% { stroke-dashoffset: 0; } } #keyframes checkmark-circle { 0% { stroke-dashoffset: 76px; } 100% { stroke-dashoffset: 0px; } } <button type="button" name="button" class="sending_btn bg-white-only m-t-25px" *ngIf="show_btn == true"> <svg class="v-middle" width="26" height="26" viewBox="-263.5 236.5 26 26"> <g class="svg-success"> <circle cx="-250.5" cy="249.5" r="12"/> <path d="M-256.46 249.65l3.9 3.74 8.02-7.8"/> </g> </svg> <span class=""> Saved</span></button> check mark and text should be appeared on the same time and completed on the same time as well. Any help would be great. Thank You.
you need to set-up some animation also for the span tag .sending_btn { outline: none; width: 128px; height: 30px; border-radius: 2px; border: thin #3a3f51 solid; transform-origin: center center; } .sending_btn span { color: #3a3f51; animation: 1.2s fadeIn; animation-fill-mode: forwards; opacity: 0; } .sending_btn:focus, .sending_btn:active { padding: 0; } svg{ vertical-align:middle; } .svg-success { stroke-width: 2px; stroke: #3a3f51; fill: none; } .svg-success path { stroke-dasharray: 17px, 17px; stroke-dashoffset: 0px; -webkit-animation: checkmark 0.25s ease-in-out 0.2s backwards; animation: checkmark 0.25s ease-in-out 0.2s backwards; } .svg-success circle { stroke-dasharray: 76px, 76px; stroke-dashoffset: 0px; transform: rotate(-90deg); transform-origin: 50% 50%; -webkit-animation: checkmark-circle 0.6s ease-in-out forwards; animation: checkmark-circle 0.6s ease-in-out forwards; } #keyframes checkmark { 0% { stroke-dashoffset: 17px; } 100% { stroke-dashoffset: 0; } } #keyframes checkmark-circle { 0% { stroke-dashoffset: 76px; } 100% { stroke-dashoffset: 0px; } } #keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } } <button type="button" name="button" class="sending_btn bg-white-only m-t-25px" *ngIf="show_btn == true"> <svg class="v-middle" width="26" height="26" viewBox="-263.5 236.5 26 26"> <g class="svg-success"> <circle cx="-250.5" cy="249.5" r="12"/> <path d="M-256.46 249.65l3.9 3.74 8.02-7.8"/> </g> </svg> <span class=""> Saved</span></button>
Stop rotation of text in loader div
I found loader CSS trick, and I want to put text or image into loader without rotation. .loader { border: 5px solid #f3f3f3; border-radius: 50%; border-top: 5px solid #fff; width: 50px; height: 50px; animation: spin 1s linear infinite; text-align: center; line-height: 50px; margin: 10px auto; font-size: 12px; } .loader > span { animation: no-spin .5s linear infinite; } #keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } #keyframes no-spin { 0% { transform: rotate(360deg); } 100% { transform: rotate(0deg); } } <div class="loader"> <span>LOGO</span> </div> I tried #keyframes no-spin for reverse rotation, but didn't work.
You'll want to add display:block on the <span>. A transform on display:inline will not work (as specified in the spec). In practice this boils down to using display:block or display:inline-block. I've also modified the animation time of .no-spin to 1s, to match your spin animation speed. This will give the illusion of not spinning, in actuality it's spinning with the same speed in the opposite direction. .loader { border: 5px solid #f3f3f3; border-radius: 50%; border-top: 5px solid #fff; width: 50px; height: 50px; animation: spin 1s linear infinite; text-align: center; line-height: 50px; margin: 10px auto; font-size: 12px; } .loader > span { display: block; animation: no-spin 1s linear infinite; } #keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } #keyframes no-spin { 0% { transform: rotate(360deg); } 100% { transform: rotate(0deg); } } <div class="loader"> <span>LOGO</span> </div>
Use the spin on a pseudo element .loader { position: relative; width: 60px; height: 60px; text-align: center; line-height: 60px; margin: 10px auto; font-size: 12px; } .loader::after { content: ''; position: absolute; top: 0; left: 0; border: 5px solid #f3f3f3; border-radius: 50%; border-top: 5px solid #fff; width: 100%; height: 100%; box-sizing: border-box; animation: spin 1s linear infinite; } #keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } <div class="loader"> <span>LOGO</span> </div>