Based on your requirements, I think that you want to put dynamic fields in a CSS file, however this is not possible since CSS is a static language. However, you can model the behavior with Angular.
Please refer to the example below. I show only one component here.
login.component.html
import { Component, OnInit } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) export class LoginComponent implements OnInit { cssProperty:any; constructor(private sanitizer: DomSanitizer) { console.log(window.innerWidth); console.log(window.innerHeight); this.cssProperty = 'position:fixed;top:' + Math.floor(window.innerHeight/3.5) + 'px;left:' + Math.floor(window.innerWidth/3) + 'px;'; this.cssProperty = this.sanitizer.bypassSecurityTrustStyle(this.cssProperty); } ngOnInit() { } }
login.component.ts
<div class="home"> <div class="container" [style]="cssProperty"> <div class="card"> <div class="card-header">Login</div> <div class="card-body">Please login</div> <div class="card-footer">Login</div> </div> </div> </div>
login.component.css
.card { max-width: 400px; } .card .card-body { min-height: 150px; } .home { background-color: rgba(171, 172, 173, 0.575); }
source share