I try to create a progress bar component in angular, everything is working except covering the parent element.
See the working code here:
See the code: Angular code: what I have now
CSS:
:host {
box-sizing: border-box;
border: 1px solid green;
display: flex;
justify-content: center;
align-items: center;
}
:host> .loader {
border: 3px solid rgba(126, 132, 138, 0.1);
border-radius: 50%;
border-top: 3px solid red;
width: 40px;
height: 40px;
-webkit-animation: spin 1s linear infinite; /* Safari */
animation: spin 1s linear infinite;
text-align: center;
display: inline-block;
z-index: 1010;
opacity: 1;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
Simple HTML:
<div class="loader" *ngIf="isLoading"></div>
2
Answers
You need a bit of CSS:
StackBlitz here
A simple way to go is changing the parent css behaviour, instead of the loading component.
Change your
.page-section
class like that inapp.component.css
Then wrap the loader component in a tag with the following style
This essentially makes the container take the whole space available and vertically and horizontally center its content.
Here is your code updated.