html - 加载程序未在 Angular 4 webapp 中居中对齐

标签 html css angular scss-lint

我想在我的 Angular 4 PWA 中添加一个加载器。 https://www.w3schools.com/howto/howto_css_loader.asp在加载页面的所有内容之前,此加载程序是可见的。

<div *ngIf="isLoaded" class="loader"></div>
<div class="home-container" [hidden]="isLoaded"></div>

最初 isLoaded 为 true,加载完所有内容后变为 false。

loader poistion => top => 0, right = 50%, left = 50%, bottom= 100%

.scss文件

.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

最佳答案

你应该把你的CSS,

  margin-right: 50%; or  margin-right: auto;
  margin-top: 50%;
  margin-left: 50%; or  margin-right: auto;

你的装载机

 .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%;
}

它在工作吗,Live working code sample

关于html - 加载程序未在 Angular 4 webapp 中居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52251329/

相关文章:

html - 为什么浏览器会调整 HTML 输入元素的大小?

ios - 禁止在 iOS 上安装 PWA,只在主屏幕上添加快捷方式

html - CSS类名长度会影响浏览器性能吗?

html - Joomla - 样式类别博客文章内容

html - 我自己的灯箱 - 响应问题

html - CSS Float 设置为向右但向左浮动

angular - 无法迭代 FormArray

html - 有条件地以 Angular 2 切换类

javascript - 为什么在这种情况下js函数需要在html文件中并且不能分开?

html - 在网页中设置iframe高度的问题