I have a big parent element that contains multiple childs elements and the parent has overflow-y: auto. When the screen size is small (400 px to 700 px) I want that one of the child component will fit to the screen size, and only the child component will be seen (without overflow).
At the beginning I thought doing it with media queries. The problem is that in media queries:
@media (min-width: 400px) and (max-width: 700px) {
//
}
It takes the window innerWidth. I saw that what I need is something like window.outerWidth (the screen size and not the content size inside the browser window).
So, I tried using:
@HostListener('window:resize', ['$event'])
private onResize(): void {
const outerWidth: number = window.outerWidth;
const smallScreenClassName: string = 'small-screen';
const isContainSmallScreen: boolean = this.el.nativeElement.classList.contains(smallScreenClassName);
this.el.nativeElement.style.width = "";
if (outerWidth >= 400 && outerWidth <= 700) {
this.el.nativeElement.classList.add(smallScreenClassName);
this.el.nativeElement.style.width = `${outerWidth}px`;
}
else if (isContainSmallScreen) {
this.el.nativeElement.classList.remove(smallScreenClassName);
}
}
But this is not good enough because I found that the outerWidth is not precise, sometimes the child component doesn't fit to the screen.
Is there any better way to do what I am trying to do?