How to show text beneath the rotating image - html

I want to show some text below the loading image.But text is aligned to different position in different browser. I have attached the screen shot of chrome and IE browser
Below is the HTML i have used
.LoaderwithText {
position: fixed;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
top: 50%;
left: 50%;
white-space: nowrap;
}
.loader {
border: 12px solid #f3f3f3;
/* Light grey */
border-top: 12px solid #3498db;
/* Blue */
border-radius: 50%;
width: 80px;
height: 80px;
-ms-animation: spin 2s linear infinite;
-webkit-animation: spin 2s linear infinite;
-o-animation: spin 2s linear infinite;
opacity: 0.5;
position: absolute;
}
#LoaderText {
Color: black;
font-size: 14px;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(-360deg);
}
}
<div class="LoaderwithText">
<a class="loader"></a>
<p id="LoaderText">Deleting...</p>
</div>
What i am missing in the style that should make it work in all browser.
IE
Chrome

If you are using flex, you need to size the container to center its content:
Absolute element can also be centered via coordonates and margin if they have a static size.
.LoaderwithText {
position: fixed;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
white-space: nowrap;
/* update*/
top: 0;
left: 0;
width:100%;
height:100%;
}
.loader {
border: 12px solid #f3f3f3;
/* Light grey */
border-top: 12px solid #3498db;
/* Blue */
border-radius: 50%;
width: 80px;
height: 80px;
-ms-animation: spin 2s linear infinite;
-webkit-animation: spin 2s linear infinite;
-o-animation: spin 2s linear infinite;
opacity: 0.5;
position: absolute;
/* update*/
top:0;
left:0;
bottom:0;
right:0;
margin:auto;
}
#LoaderText {
Color: black;
font-size: 14px;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(-360deg);
}
}
<div class="LoaderwithText">
<a class="loader"></a>
<p id="LoaderText">Deleting...</p>
</div>

Related

Spinner acting out

Any ideas of what is happening here? Why does the purple box position itself outside the spinner for a moment there?
This is my css and rotate animation:
.spinner {
display: flex;
align-items: center;
justify-content: center;
background-color: red;
}
.spinner-ball {
border: 2px solid blue;
border-bottom-color: transparent;
border-radius: 100%;
height: 26px;
width: 26px;
background: transparent !important;
display: inline-block;
animation-fill-mode: both;
-webkit-animation-fill-mode: both;
animation: rotate 1s linear infinite;
-webkit-animation: rotate 1s linear infinite;
}
#keyframes rotate {
from {
transform: rotate(0deg);
-webkit-transform: rotate(0deg);
}
to {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
}
}
<div class="spinner">
<div class="spinner-ball" />
</div>

loader is not aligning in center in angular 4 webapp

I want to add an loader in my angular 4 PWA. https://www.w3schools.com/howto/howto_css_loader.asp this loader is visible till all the contents of page get loaded.
<div *ngIf="isLoaded" class="loader"></div>
<div class="home-container" [hidden]="isLoaded"></div>
Initially isLoaded is true after loading all contents it will become false.
loader poistion => top => 0, right = 50%, left = 50%, bottom= 100%
.scss file
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #59d4bf; /* green */
border-radius: 50%;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
here -stackblitz live code sample
Your should put your css,
margin-right: 50%; or margin-right: auto;
margin-top: 50%;
margin-left: 50%; or margin-right: auto;
your loader
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin-left: 50%;
margin-right: 50%;
margin-top: 50%;
}
is it working , Live working code sample

How to center a div (CSS loader)

JS Fiddle: fiddle and here is the code:
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader"></div>
How do I centre it horizontally & vertically?
I tried:
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
But transform:translate(-50%,-50%); do not work
Give below css to .loader class:
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
position:fixed;
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
position:fixed;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader"></div>
You can make it position:absolute;
and give it:
top:0;
left:0;
right:0;
bottom:0;
to make it both vertically and horizontally aligned into the middle.
body {
overflow:hidden;
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
margin:auto;
top:0;
left:0;
bottom:0;
right:0;
position:absolute;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader"></div>
Easiest way to center element using CSS is by using flexbox. No hacks required.
if need to set parent container with display: flex.
<div class="container">
<div class="item">
Aligned Item
<div>
</div>
CSS:
.container {
display: flex;
align-items: center;
justify-content: center;
}
.item {
width: 200px;
height: 200px;
}
All elements with class item will be centrally aligned.
More details can be found at
https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/
Several ways to do it.
Using flexbox. This would work in any container anywhere on the page.
body { /* or some wrapper, if you plan to have other things in body */
min-height: 100vh; /* this just expands the body height so the vertical alignment is visible in the snippet */
display: flex;
justify-content: center; /* center horizontally */
align-items: center; /* center vertically */
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader"></div>
Using position: absolute. This centers the div relative to the document, not loader's parent element.
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
/* i added this: */
position: absolute;
left: calc(50% - 120px / 2); /* 50 % of body width minus half of .loader size… */
top: calc(50% - 120px / 2); /* …and the same thing with height */
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<div class="loader"></div>
Please add body {height: 100vh;} and update the css of loader div as the following:
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
margin: auto;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
https://jsfiddle.net/7baw2rmp/

Simple CSS spinner works as a DIV but not as a SPAN (or inline DIV)

I need a spinner that I can basically insert into the middle of paragraph text. I have the spinner the way I want it as a block-display element (div), but when I try to create it as a span (or change the div to be inline), the spinner doesn't work.
How can I modify this spinner so that it can be dropped into the middle of a sentence (i.e., paragraph text)?
#loader {
float: left;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#loaderInline {
display: inline;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
#-webkit-keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0px;
opacity: 1
}
}
#keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0;
opacity: 1
}
}
<p>
<div id="loader"></div>Works as normal DIV
</p>
<p>
<div id="loaderInline"></div>Broken as DIV with inline display
</p>
inline element cannot be sized , inline-block, inline-flex or inline-table does and interact as an inline box.
#loader {
float: left;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#loaderInline {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
#-webkit-keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0px;
opacity: 1
}
}
#keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0;
opacity: 1
}
}
<p>
<div id="loader"></div>Works as normal DIV
</p>
<p>
<div id="loaderInline"></div>Broken as DIV with inline display
</p>
You may as well use a pseudo :before/::before and inline-block:
#loader {
float: left;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
p:before {
content: '';
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
margin-top: 2px;
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
#-webkit-keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0px;
opacity: 1
}
}
#keyframes animatebottom {
from {
bottom: -100px;
opacity: 0
}
to {
bottom: 0;
opacity: 1
}
}
<p>
an inline-block pseudo works too;
</p>

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>